﻿namespace NEvoWeb.Modules.NB_Store
{
    using DotNetNuke.Common;
    using DotNetNuke.Common.Lists;
    using DotNetNuke.Common.Utilities;
    using DotNetNuke.Entities.Host;
    using DotNetNuke.Entities.Portals;
    using DotNetNuke.Entities.Tabs;
    using DotNetNuke.Entities.Users;
    using DotNetNuke.Security;
    using DotNetNuke.Security.Permissions;
    using DotNetNuke.Services.Exceptions;
    using DotNetNuke.Services.FileSystem;
    using DotNetNuke.Services.Localization;
    using DotNetNuke.Services.Mail;
    using DotNetNuke.UI.UserControls;
    using System;
    using System.Collections;
    using System.Drawing;
    using System.Globalization;
    using System.IO;
    using System.Reflection;
    using System.Runtime.CompilerServices;
    using System.Runtime.InteropServices;
    using System.Text;
    using System.Text.RegularExpressions;
    using System.Threading;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Xml;
    using System.Xml.XPath;
    using System.Xml.Xsl;

    public class SharedFunctions
    {
        public const string DSEDITLOCAL = "DSEditLocale";
        public const string NBSTOREAPPNAME = "NB_Store";
        public const string NBSTORERESX = "/DesktopModules/NB_Store/App_LocalResources/NB_StoreGlobal";
        public const string ORDERUPLOADFOLDER = "orderuploads";
        public const string PRODUCTDOCSFOLDER = "productdocs";
        public const string PRODUCTIMAGESFOLDER = "productimages";
        public const string PRODUCTTHUMBSFOLDER = "productthumbs";
        public const string STOREPREFIX = "NB_Store2_";
        public const string TEMPLATEFOLDER = "NB_Store_Templates";

        public static void AddCSSLink(string LinkFile, Page Page)
        {
            HtmlLink child = new HtmlLink();
            if (!LinkFile.EndsWith("/"))
            {
                child.Attributes["rel"] = "stylesheet";
                child.Attributes["media"] = "screen";
                child.Attributes["type"] = "text/css";
                child.Attributes["href"] = LinkFile;
                Control control = Page.FindControl("CSS");
                if (control != null)
                {
                    control.Controls.Add(child);
                }
            }
        }

        public static object assignByReflection(object obj, string TagXMLString)
        {
            return assignByReflection(RuntimeHelpers.GetObjectValue(obj), getTokenPropXMLnode(TagXMLString));
        }

        public static object assignByReflection(object obj, XmlNode xmlNod)
        {
            IEnumerator enumerator=null;
            try
            {
                enumerator = xmlNod.Attributes.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    XmlAttribute current = (XmlAttribute) enumerator.Current;
                    obj = RuntimeHelpers.GetObjectValue(assignByReflection(RuntimeHelpers.GetObjectValue(obj), current.Name, current.InnerText));
                }
            }
            finally
            {
                if (enumerator!=null && enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
            return obj;
        }

        public static object assignByReflection(object obj, string PropName, string PropValue)
        {
            try
            {
                PropertyInfo property = obj.GetType().GetProperty(PropName, BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase);
                if (property == null)
                {
                    return obj;
                }
                switch (property.PropertyType.Name)
                {
                    case "Int32":
                    case "Integer":
                    case "Int16":
                    case "Int64":
                        property.SetValue(RuntimeHelpers.GetObjectValue(obj), Convert.ToInt32(PropValue), null);
                        return obj;

                    case "Boolean":
                        property.SetValue(RuntimeHelpers.GetObjectValue(obj), Convert.ToBoolean(PropValue), null);
                        return obj;

                    case "String":
                        property.SetValue(RuntimeHelpers.GetObjectValue(obj), PropValue, null);
                        return obj;

                    case "Unit":
                        property.SetValue(RuntimeHelpers.GetObjectValue(obj), Unit.Parse(PropValue), null);
                        return obj;
                }
                if (Enum.IsDefined(property.PropertyType, PropValue))
                {
                    property.SetValue(RuntimeHelpers.GetObjectValue(obj), RuntimeHelpers.GetObjectValue(Enum.Parse(property.PropertyType, PropValue, true)), null);
                    return obj;
                }
                if (Versioned.IsNumeric(PropValue))
                {
                    property.SetValue(RuntimeHelpers.GetObjectValue(obj), Convert.ToInt32(PropValue), null);
                    return obj;
                }
                property.SetValue(RuntimeHelpers.GetObjectValue(obj), PropValue, null);
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                ProjectData.ClearProjectError();
            }
            return obj;
        }

        public static void BuildCategoryList(ArrayList aryList, int ParentID, string Prefix, ArrayList aryRtn)
        {
            IEnumerator enumerator=null;
            string categoryName = "";
            try
            {
                enumerator = aryList.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    NB_Store_CategoriesInfo current = (NB_Store_CategoriesInfo) enumerator.Current;
                    if (current.ParentCategoryID == ParentID)
                    {
                        ListItem item = new ListItem {
                            Value = current.CategoryID.ToString(),
                            Text = Prefix + current.CategoryName
                        };
                        aryRtn.Add(item);
                        if (current.CategoryName.Length > 20)
                        {
                            categoryName = current.CategoryName.Substring(0, 0x12) + "..";
                        }
                        else
                        {
                            categoryName = current.CategoryName;
                        }
                        BuildCategoryList(aryList, current.CategoryID, Prefix + categoryName + ">", aryRtn);
                    }
                }
            }
            finally
            {
                if (enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
        }

        public static void BuildCategoryList(ArrayList aryList, DropDownList ddlCategories, int ParentID, string Prefix)
        {
            IEnumerator enumerator=null;
            try
            {
                enumerator = aryList.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    NB_Store_CategoriesInfo current = (NB_Store_CategoriesInfo) enumerator.Current;
                    if (current.ParentCategoryID == ParentID)
                    {
                        ListItem item = new ListItem {
                            Value = current.CategoryID.ToString(),
                            Text = Prefix + current.CategoryName
                        };
                        ddlCategories.Items.Add(item);
                        BuildCategoryList(aryList, ddlCategories, current.CategoryID, Prefix + ".");
                    }
                }
            }
            finally
            {
                if (enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
        }

        public static string CategoryPageName(NB_Store_CategoriesInfo CategoryListInfo, string PortalName)
        {
            string expression = PortalName;
            if (CategoryListInfo == null)
            {
                return expression;
            }
            string cacheKey = "CATPG" + CategoryListInfo.CategoryID.ToString() + "_" + CategoryListInfo.Lang;
            if ((DataCache.GetCache(cacheKey) == null) | GetStoreSettingBoolean(CategoryListInfo.PortalID, "debug.mode"))
            {
                expression = GetStoreSettingText(CategoryListInfo.PortalID, "categorypagename.template", CategoryListInfo.Lang);
                if (expression == "")
                {
                    expression = String.Replace(CategoryListInfo.SEOPageTitle, "[TAG:PORTALNAME]", PortalName, 1, -1, CompareMethod.Binary);
                    if (expression == "")
                    {
                        expression = CategoryListInfo.CategoryDesc;
                    }
                    if (expression == "")
                    {
                        expression = PortalName;
                    }
                }
                else
                {
                    expression = String.Replace(expression, "[TAG:PORTALNAME]", PortalName, 1, -1, CompareMethod.Binary);
                    if (CategoryListInfo.SEOPageTitle == "")
                    {
                        expression = new TokenStoreReplace(CategoryListInfo).DoTokenReplace(expression);
                    }
                    else
                    {
                        expression = CategoryListInfo.SEOPageTitle;
                    }
                }
                DataCache.SetCache(cacheKey, expression, DateAndTime.DateAdd(DateInterval.Day, 1.0, DateAndTime.Now));
                return expression;
            }
            return Convert.ToString(DataCache.GetCache(cacheKey));
        }

        public static void ClearProductCache(int PortalID, int ProductID)
        {
            Hashtable cache = (Hashtable) DataCache.GetCache("NB_StoreProdKeyList_" + PortalID.ToString());
            if ((cache != null) && cache.ContainsKey(ProductID))
            {
                IDictionaryEnumerator enumerator = ((Hashtable) cache[ProductID]).GetEnumerator();
                while (enumerator.MoveNext())
                {
                    DictionaryEntry current = (DictionaryEntry) enumerator.Current;
                    DataCache.RemoveCache(Conversions.ToString(current.Value));
                }
            }
        }

        public static void CreateDir(PortalSettings PortalSettings, string FolderName)
        {
            bool flag = false;
            try
            {
                flag = Directory.Exists(PortalSettings.HomeDirectoryMapPath + FolderName);
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                flag = false;
                ProjectData.ClearProjectError();
            }
            if (!flag && ((FileSystemUtils.GetFolder(PortalSettings.PortalId, FolderName) == null) & (FolderName != "")))
            {
                FolderController controller = new FolderController();
                FileSystemUtils.AddFolder(PortalSettings, PortalSettings.HomeDirectoryMapPath, FolderName);
                FolderInfo folder = FileSystemUtils.GetFolder(PortalSettings.PortalId, FolderName);
                if (folder != null)
                {
                    IEnumerator enumerator;
                    int folderID = folder.FolderID;
                    ArrayList permissionByCodeAndKey = new PermissionController().GetPermissionByCodeAndKey("SYSTEM_FOLDER", "");
                    try
                    {
                        enumerator = permissionByCodeAndKey.GetEnumerator();
                        while (enumerator.MoveNext())
                        {
                            PermissionInfo current = (PermissionInfo) enumerator.Current;
                            if (current.PermissionKey == "WRITE")
                            {
                                FileSystemUtils.SetFolderPermission(PortalSettings.PortalId, folderID, current.PermissionID, int.Parse("-1"), "");
                            }
                        }
                    }
                    finally
                    {
                        if (enumerator is IDisposable)
                        {
                            (enumerator as IDisposable).Dispose();
                        }
                    }
                }
            }
        }

        public static decimal CurrencyStringToDecimal(int PortalID, string Value)
        {
            if (Value.Length == 0)
            {
                return decimal.Zero;
            }
            string expression = GetStoreSetting(PortalID, "currency.culture", GetCurrentCulture());
            if (expression.StartsWith("\""))
            {
                return Conversions.ToDecimal(Conversions.ToDouble(Value).ToString(Strings.Replace(expression, "\"", "", 1, -1, CompareMethod.Binary)));
            }
            if (expression == "")
            {
                expression = GetMerchantCulture(PortalID);
            }
            CultureInfo info = new CultureInfo(expression, false);
            return decimal.Parse(Value, NumberStyles.Any, info.NumberFormat);
        }

        public static void Display404Error(int PortalID, HttpResponse Response, HttpServerUtility Server)
        {
            string path = GetStoreSetting(PortalID, "err404.url", GetCurrentCulture());
            if (path != "")
            {
                Response.StatusCode = 0x194;
                Server.Transfer(path);
                Response.End();
            }
        }

        public static void DisplayMsgText(string PortalId, PlaceHolder plHolder, string TextTemplateID, string DefaultMsg)
        {
            string s = GetMsgText(PortalId, TextTemplateID, DefaultMsg);
            plHolder.Controls.Add(new LiteralControl(HttpUtility.HtmlDecode(s)));
        }

        public static void DisplayXMLData(object objInfo, DataList dlXMLData)
        {
            ArrayList list = new ArrayList();
            list.Add(RuntimeHelpers.GetObjectValue(objInfo));
            dlXMLData.DataSource = list;
            dlXMLData.DataBind();
        }

        public static bool DocHasBeenPurchased(int UserID, int ProductID)
        {
            if (UserID >= 0)
            {
                ProductController controller = new ProductController();
                return (controller.CheckIfProductPurchased(ProductID, UserID) > 0);
            }
            return false;
        }

        public static bool DocHasBeenPurchasedByDocID(int UserID, int DocID)
        {
            NB_Store_ProductDocInfo productDoc = new ProductController().GetProductDoc(DocID, GetCurrentCulture());
            return DocHasBeenPurchased(UserID, productDoc.ProductID);
        }

        public static void DoModuleImport(int ModuleID, string ImpFileName, int usrID)
        {
            if (ImpFileName != "")
            {
                XmlDataDocument document = new XmlDataDocument();
                BasePortController controller = new BasePortController();
                ManagerMenuController controller2 = new ManagerMenuController();
                document.Load(ImpFileName);
                if (document.SelectSingleNode("content/modulecontent") != null)
                {
                    controller.ImportModule(ModuleID, document.SelectSingleNode("content/modulecontent").OuterXml, "1", usrID);
                }
                if (document.SelectSingleNode("content/storecontent") != null)
                {
                    controller2.ImportModule(ModuleID, document.SelectSingleNode("content/storecontent").OuterXml, "1", usrID);
                }
            }
        }

        public static Bitmap EmbeddedImage(string Name)
        {
            return new Bitmap(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(Name));
        }

        public static void ForceStringDownload(HttpResponse Response, string FileName, string FileData)
        {
            Response.AppendHeader("content-disposition", "attachment; filename=" + FileName);
            Response.ContentType = "application/octet-stream";
            Response.Write(FileData);
            Response.End();
        }

        public static string FormatFromSave(string inpData, TypeCode DataTyp = 0x12, string SaveLang = "en-GB")
        {
            if (inpData != "")
            {
                CultureInfo provider = new CultureInfo("en-GB", false);
                switch (((int) DataTyp))
                {
                    case 14:
                        return double.Parse(inpData, provider).ToString();

                    case 15:
                        return inpData;

                    case 0x10:
                        return DateTime.Parse(inpData).ToString("d");
                }
            }
            return inpData;
        }

        public static string FormatToSave(string inpData, TypeCode DataTyp = 0x12, string SaveLang = "en-GB")
        {
            if (inpData != "")
            {
                CultureInfo provider = new CultureInfo(SaveLang, false);
                switch (((int) DataTyp))
                {
                    case 14:
                        if (!Versioned.IsNumeric(inpData))
                        {
                            return Conversions.ToString(0);
                        }
                        return Conversions.ToDouble(inpData).ToString("N", provider);

                    case 15:
                        return inpData;

                    case 0x10:
                        DateTime time;
                        if (Information.IsDate(time))
                        {
                            return Conversions.ToDate(inpData).ToString("s");
                        }
                        return "";
                }
            }
            return inpData;
        }

        public static string FormatToStoreCurrency(double Value)
        {
            return FormatToStoreCurrency(PortalController.GetCurrentPortalSettings().PortalId, Value);
        }

        public static string FormatToStoreCurrency(int PortalID, double Value)
        {
            string expression = GetStoreSetting(PortalID, "currency.culture", GetCurrentCulture());
            if (expression == "")
            {
                expression = GetMerchantCulture(PortalID);
            }
            string str3 = "";
            if (expression.StartsWith("\""))
            {
                return Value.ToString(Strings.Replace(expression, "\"", "", 1, -1, CompareMethod.Binary));
            }
            try
            {
                str3 = Value.ToString("c", new CultureInfo(expression, false));
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                str3 = Value.ToString();
                ProjectData.ClearProjectError();
            }
            return str3;
        }

        public static string getAdminCookieValue(int PortalID, string ValueID)
        {
            return getStoreCookieValue(PortalID, "Admin", ValueID);
        }

        public static string GetAdministratorEmail(int PortalID)
        {
            NB_Store_SettingsInfo info = new SettingsController().GetSetting(PortalID, "administrator.email", "None");
            if (info == null)
            {
                return "";
            }
            return info.SettingValue;
        }

        public static ArrayList GetAvailableGateways(int PortalID)
        {
            NB_Store_GatewayInfo info;
            XmlNode current;
            IEnumerator enumerator;
            IEnumerator enumerator2;
            ArrayList list = new ArrayList();
            string str = GetStoreSetting(PortalID, "gateway.provider", "XX");
            XmlDataDocument document = new XmlDataDocument();
            string xml = GetStoreSetting(PortalID, "gatewayproviders.xml", GetCurrentCulture(), true);
            document.LoadXml(xml);
            try
            {
                enumerator = document.SelectNodes("root/gateways/gateway").GetEnumerator();
                while (enumerator.MoveNext())
                {
                    current = (XmlNode) enumerator.Current;
                    if ((current.SelectSingleNode("assembly") != null) && (Strings.InStr(str, current.SelectSingleNode("assembly").InnerText, CompareMethod.Binary) >= 0))
                    {
                        info = new NB_Store_GatewayInfo {
                            @ref = current.Attributes["ref"].InnerText,
                            name = current.SelectSingleNode("name").InnerText,
                            assembly = current.SelectSingleNode("assembly").InnerText,
                            classname = current.SelectSingleNode("name").InnerText
                        };
                        if (current.SelectSingleNode("gatewaymsg") != null)
                        {
                            info.gatewaymsg = current.SelectSingleNode("gatewaymsg").InnerText;
                        }
                        else
                        {
                            info.gatewaymsg = current.SelectSingleNode("name").InnerText;
                        }
                        info.gatewaytype = "PRO";
                        list.Add(info);
                    }
                }
            }
            finally
            {
                if (enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
            str = GetStoreSetting(PortalID, "encapsulated.provider", "XX");
            xml = GetStoreSetting(PortalID, "encapsulatedproviders.xml", GetCurrentCulture(), true);
            document = new XmlDataDocument();
            document.LoadXml(xml);
            try
            {
                enumerator2 = document.SelectNodes("root/gateways/gateway").GetEnumerator();
                while (enumerator2.MoveNext())
                {
                    current = (XmlNode) enumerator2.Current;
                    if ((current.SelectSingleNode("assembly") != null) && (Strings.InStr(str, current.SelectSingleNode("assembly").InnerText, CompareMethod.Binary) >= 0))
                    {
                        info = new NB_Store_GatewayInfo {
                            @ref = current.Attributes["ref"].InnerText,
                            name = current.SelectSingleNode("name").InnerText,
                            assembly = current.SelectSingleNode("assembly").InnerText,
                            classname = current.SelectSingleNode("name").InnerText
                        };
                        if (current.SelectSingleNode("gatewaymsg") != null)
                        {
                            info.gatewaymsg = current.SelectSingleNode("gatewaymsg").InnerText;
                        }
                        else
                        {
                            info.gatewaymsg = current.SelectSingleNode("name").InnerText;
                        }
                        info.gatewaytype = "CHQ";
                        list.Add(info);
                    }
                }
            }
            finally
            {
                if (enumerator2 is IDisposable)
                {
                    (enumerator2 as IDisposable).Dispose();
                }
            }
            return list;
        }

        public static Hashtable GetAvailableGatewaysTable(int PortalID)
        {
            IEnumerator enumerator;
            Hashtable hashtable2 = new Hashtable();
            ArrayList availableGateways = GetAvailableGateways(PortalID);
            try
            {
                enumerator = availableGateways.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    NB_Store_GatewayInfo current = (NB_Store_GatewayInfo) enumerator.Current;
                    hashtable2.Add(current.@ref, current);
                }
            }
            finally
            {
                if (enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
            return hashtable2;
        }

        public static ArrayList GetAvailableModelList(int PortalID, int ProductID, string Lang, bool IsDealer)
        {
            ArrayList list;
            int num2;
            ProductController controller = new ProductController();
            if (!GetStoreSettingBoolean(PortalID, "outofstockmodels.flag"))
            {
                list = controller.GetModelInStockList(ProductID, Lang, IsDealer);
                return CurrentCart.AdjustCartStockInModels(PortalID, list);
            }
            list = controller.GetModelList(PortalID, ProductID, Lang, IsDealer);
            int index = list.Count - 1;
        Label_0053:
            num2 = 0;
            if (index >= num2)
            {
                if (((NB_Store_ModelInfo) list[index]).Deleted)
                {
                    list.RemoveAt(index);
                }
                index += -1;
                goto Label_0053;
            }
            return list;
        }

        public static string GetCacheKey(string KeyID, int PortalID)
        {
            return GetCacheKey(KeyID, PortalID, -1);
        }

        public static string GetCacheKey(string KeyID, int PortalID, int ProductID)
        {
            string key = "";
            key = "NB_Store" + KeyID + "_" + PortalID.ToString() + "_" + ProductID.ToString();
            if (ProductID >= 0)
            {
                Hashtable hashtable2;
                string cacheKey = "NB_StoreProdKeyList_" + PortalID.ToString();
                Hashtable cache = (Hashtable) DataCache.GetCache(cacheKey);
                if (cache == null)
                {
                    cache = new Hashtable();
                    hashtable2 = new Hashtable();
                    hashtable2.Add(key, key);
                    cache.Add(ProductID, hashtable2);
                    DataCache.SetCache(cacheKey, cache);
                    return key;
                }
                if (cache.ContainsKey(ProductID))
                {
                    hashtable2 = (Hashtable) cache[ProductID];
                    if (!hashtable2.ContainsKey(key))
                    {
                        hashtable2.Add(key, key);
                        cache.Remove(ProductID);
                        cache.Add(ProductID, hashtable2);
                        DataCache.SetCache(cacheKey, cache);
                    }
                    return key;
                }
                hashtable2 = new Hashtable();
                hashtable2.Add(key, key);
                cache.Add(ProductID, hashtable2);
                DataCache.SetCache(cacheKey, cache);
            }
            return key;
        }

        public static string GetClientEmail(int portalid, NB_Store_OrdersInfo objOInfo)
        {
            UserController controller = new UserController();
            string email = "";
            if (objOInfo.Email == "")
            {
                UserInfo user = controller.GetUser(portalid, objOInfo.UserID);
                if (user != null)
                {
                    email = user.Email;
                }
                return email;
            }
            return objOInfo.Email;
        }

        public static string GetClientLang(int portalid, NB_Store_OrdersInfo objOInfo)
        {
            return GetClientLang(portalid, objOInfo.UserID);
        }

        public static string GetClientLang(int portalid, int Userid)
        {
            string currentCulture = GetCurrentCulture();
            UserInfo user = new UserController().GetUser(portalid, Userid);
            if (user != null)
            {
                currentCulture = user.Profile.PreferredLocale;
            }
            if (currentCulture == "")
            {
                currentCulture = GetCurrentCulture();
            }
            return currentCulture;
        }

        public static string getCookieQueryValue(int PortalID, string CookieValueName, HttpCookie ListCookie, HttpRequest Request)
        {
            return getCookieQueryValue(PortalID, CookieValueName, ListCookie, Request, "");
        }

        public static string getCookieQueryValue(int PortalID, string CookieValueName, HttpCookie ListCookie, HttpRequest Request, string DefaultReturn)
        {
            string str2 = "";
            if (Request.QueryString[CookieValueName] != null)
            {
                str2 = Request.QueryString[CookieValueName];
                setStoreCookieValue(PortalID, ListCookie, CookieValueName, str2.ToString(), 0.0);
            }
            else
            {
                str2 = getStoreCookieValue(PortalID, ListCookie, CookieValueName);
            }
            if (str2 == "")
            {
                str2 = DefaultReturn;
            }
            return str2;
        }

        public static int getCookieQueryValueInt(int PortalID, string CookieValueName, HttpCookie ListCookie, HttpRequest Request, int DefaultReturn)
        {
            string expression = getCookieQueryValue(PortalID, CookieValueName, ListCookie, Request);
            if (Versioned.IsNumeric(expression))
            {
                return Conversions.ToInteger(expression);
            }
            return DefaultReturn;
        }

        public static object getCookieURLparam(int PortalID, string ValueID)
        {
            return getStoreCookieValue(PortalID, "UrlCookieInfo", ValueID);
        }

        public static string GetCountryByCode(string CountryCode)
        {
            ListEntryInfoCollection listEntryInfoCollection = new ListController().GetListEntryInfoCollection("Country", CountryCode);
            if (listEntryInfoCollection.Count == 0)
            {
                return "";
            }
            return listEntryInfoCollection.Item(0).Text;
        }

        public static string getCurrencyISOCode()
        {
            return getCurrencyISOCode(PortalController.GetCurrentPortalSettings().PortalId);
        }

        public static string getCurrencyISOCode(int PortalID)
        {
            string name = GetStoreSetting(PortalID, "currency.culture", GetCurrentCulture());
            if (name == "")
            {
                name = GetMerchantCulture(PortalID);
            }
            string iSOCurrencySymbol = "";
            try
            {
                iSOCurrencySymbol = new RegionInfo(name).ISOCurrencySymbol;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                iSOCurrencySymbol = "";
                ProjectData.ClearProjectError();
            }
            return iSOCurrencySymbol;
        }

        public static string getCurrencySymbol()
        {
            return getCurrencySymbol(PortalController.GetCurrentPortalSettings().PortalId);
        }

        public static string getCurrencySymbol(int PortalID)
        {
            string name = GetStoreSetting(PortalID, "currency.culture", GetCurrentCulture());
            string currencySymbol = "";
            if ((name == "") | name.StartsWith("\""))
            {
                currencySymbol = GetStoreSetting(PortalID, "currency.symbol", GetCurrentCulture());
            }
            if (currencySymbol == "")
            {
                name = GetMerchantCulture(PortalID);
                try
                {
                    currencySymbol = new CultureInfo(name, false).NumberFormat.CurrencySymbol;
                }
                catch (Exception exception1)
                {
                    ProjectData.SetProjectError(exception1);
                    Exception exception = exception1;
                    ProjectData.ClearProjectError();
                }
            }
            return currencySymbol;
        }

        public static string GetCurrentCountryCode()
        {
            return Thread.CurrentThread.CurrentCulture.Name.Substring(3, 2);
        }

        public static string GetCurrentCulture()
        {
            return Thread.CurrentThread.CurrentCulture.ToString();
        }

        public static string GetCurrentLangCode()
        {
            return Thread.CurrentThread.CurrentCulture.Name.Substring(0, 2);
        }

        public static int GetDefaultShipMethod(int PortalID)
        {
            string cacheKey = "DefaultShipMethod" + PortalID.ToString();
            if (DataCache.GetCache(cacheKey) == null)
            {
                NB_Store_ShippingMethodInfo info;
                ArrayList shippingMethodList = new ShipController().GetShippingMethodList(PortalID);
                if (shippingMethodList.Count > 0)
                {
                    info = (NB_Store_ShippingMethodInfo) shippingMethodList[0];
                }
                else
                {
                    return -1;
                }
                DataCache.SetCache(cacheKey, info.ShipMethodID, DateAndTime.DateAdd(DateInterval.Hour, 1.0, DateAndTime.Now));
                return info.ShipMethodID;
            }
            return Conversions.ToInteger(DataCache.GetCache(cacheKey));
        }

        public static Hashtable getDocsFileNamesInDB(int PortalID)
        {
            IEnumerator enumerator;
            Hashtable hashtable2 = new Hashtable();
            ProductController controller = new ProductController();
            NB_Store_ProductDocInfo current = new NB_Store_ProductDocInfo();
            ArrayList productDocExportList = controller.GetProductDocExportList(PortalID);
            try
            {
                enumerator = productDocExportList.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    current = (NB_Store_ProductDocInfo) enumerator.Current;
                    if (!hashtable2.ContainsKey(Path.GetFileName(current.DocPath)))
                    {
                        hashtable2.Add(Path.GetFileName(current.DocPath), Path.GetFileName(current.DocPath));
                    }
                }
            }
            finally
            {
                if (enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
            return hashtable2;
        }

        public static string GetFeederReportText(HttpContext context, bool FormatAsXML)
        {
            string objObject = "";
            string key = getURLParam(context, "key");
            string str6 = getURLParam(context, "ProdID");
            string str7 = getURLParam(context, "ProdRef");
            string expression = getURLParam(context, "CatID");
            string lang = getURLParam(context, "Lang");
            string str8 = getURLParam(context, "Search");
            string str5 = getURLParam(context, "pass");
            string storeTabID = getURLParam(context, "TabID");
            int portalId = PortalController.GetCurrentPortalSettings().PortalId;
            string cacheKey = key + str5 + str6 + expression + Conversions.ToString(FormatAsXML);
            bool flag = GetStoreSettingBoolean(portalId, "debug.mode", "None");
            if (lang == "")
            {
                lang = GetMerchantCulture(portalId);
            }
            if (FormatAsXML)
            {
                objObject = "<root></root>";
            }
            if (!((getLangCache(portalId, cacheKey, lang) == null) | flag))
            {
                return getLangCache(portalId, cacheKey, lang).ToString();
            }
            Hashtable hashtable = populateFeederSettings(portalId);
            if (hashtable == null)
            {
                return "Invalid \"feeder.settings\" setting";
            }
            if (hashtable.Contains(key))
            {
                FeederSetInfo info = (FeederSetInfo) hashtable[key];
                if ((info.reportref != "") & (str5 == info.password))
                {
                    SQLReportController controller = new SQLReportController();
                    NB_Store_SQLReportInfo sQLReportByRef = controller.GetSQLReportByRef(portalId, info.reportref);
                    if ((sQLReportByRef != null) && (sQLReportByRef.SQL != ""))
                    {
                        sQLReportByRef.SQL = controller.insertParams(sQLReportByRef.ReportID, -1, portalId, context.Request, sQLReportByRef.SQL, GetCurrentCulture());
                        if (FormatAsXML)
                        {
                            objObject = controller.runXSL(sQLReportByRef);
                            if (objObject == "")
                            {
                                try
                                {
                                    objObject = controller.ExecuteSQLReportXml(sQLReportByRef.SQL);
                                }
                                catch (Exception exception1)
                                {
                                    ProjectData.SetProjectError(exception1);
                                    objObject = "ERROR runnig ExecuteSQLReportXml:   " + exception1.ToString();
                                    ProjectData.ClearProjectError();
                                }
                            }
                        }
                        else
                        {
                            try
                            {
                                objObject = controller.ExecuteSQLReportText(sQLReportByRef.SQL, sQLReportByRef.FieldDelimeter, sQLReportByRef.FieldQualifier, sQLReportByRef.AllowDisplay);
                            }
                            catch (Exception exception3)
                            {
                                ProjectData.SetProjectError(exception3);
                                objObject = "ERROR runnig ExecuteSQL:   " + exception3.ToString();
                                ProjectData.ClearProjectError();
                            }
                        }
                        if ((Conversions.ToInteger(info.cachemins) > 0) & !objObject.StartsWith("ERROR"))
                        {
                            if (FormatAsXML)
                            {
                                objObject = "<root>" + objObject + "</root>";
                            }
                            setLangCache(portalId, cacheKey, lang, objObject, Conversions.ToInteger(info.cachemins));
                        }
                    }
                }
                else if (flag & (info.functionkey == ""))
                {
                    objObject = "Invalid Password for Report: " + info.Key;
                }
                if (info.functionkey != "")
                {
                    ProductController controller2 = new ProductController();
                    Export export = new Export();
                    if (((info.functionkey == "xmlGetProductsInCat") & Versioned.IsNumeric(portalId)) & Versioned.IsNumeric(expression))
                    {
                        objObject = controller2.xmlGetProductsInCat(portalId, Conversions.ToInteger(expression), lang, -1);
                    }
                    else if (info.functionkey == "xmlGetProduct")
                    {
                        objObject = export.GetProductXML(Conversions.ToInteger(str6), lang);
                    }
                    else if ((((info.functionkey == "xmlGetRSS") & Versioned.IsNumeric(portalId)) & Versioned.IsNumeric(expression)) && (Conversions.ToDouble(expression) >= 0.0))
                    {
                        objObject = getRSSoutput(controller2.GetProductList(portalId, Conversions.ToInteger(expression), lang, false), storeTabID);
                    }
                    setLangCache(portalId, cacheKey, lang, objObject, Conversions.ToInteger(info.cachemins));
                }
            }
            return objObject;
        }

        public static string getGenXML(DataList dlGenXML, int RowIndex = 0, string Lang = "en-GB")
        {
            return getGenXML(dlGenXML, "", "", RowIndex, Lang);
        }

        public static string getGenXML(DataList dlGenXML, string OriginalXML, string FolderMapPath = "", int RowIndex = 0, string Lang = "en-GB")
        {
            Collection collection3 = new Collection();
            Collection collection6 = new Collection();
            Collection collection2 = new Collection();
            Collection collection8 = new Collection();
            Collection collection5 = new Collection();
            Collection collection4 = new Collection();
            Collection collection = new Collection();
            Collection collection7 = new Collection();
            if ((dlGenXML.Items.Count > RowIndex) && (dlGenXML.Items.Count >= 1))
            {
                IEnumerator enumerator;
                IEnumerator enumerator2;
                IEnumerator enumerator3;
                IEnumerator enumerator4;
                IEnumerator enumerator5;
                IEnumerator enumerator7;
                IEnumerator enumerator8;
                DataListItem item = dlGenXML.Items[RowIndex];
                try
                {
                    enumerator = item.Controls.GetEnumerator();
                    while (enumerator.MoveNext())
                    {
                        Control current = (Control) enumerator.Current;
                        if (current is DropDownList)
                        {
                            collection3.Add(current, null, null, null);
                        }
                        if (current is CheckBoxList)
                        {
                            collection2.Add(current, null, null, null);
                        }
                        if (current is CheckBox)
                        {
                            collection.Add(current, null, null, null);
                        }
                        if ((current is TextBox) | (current is DateEditControl))
                        {
                            if (current is DateEditControl)
                            {
                                collection8.Add(((DateEditControl) current).dateField, null, null, null);
                            }
                            else
                            {
                                collection8.Add(current, null, null, null);
                            }
                        }
                        if (current is RadioButtonList)
                        {
                            collection6.Add(current, null, null, null);
                        }
                        if (current is GenTextEditor)
                        {
                            collection7.Add(current, null, null, null);
                        }
                    }
                }
                finally
                {
                    if (enumerator is IDisposable)
                    {
                        (enumerator as IDisposable).Dispose();
                    }
                }
                XmlDataDocument xmlDoc = new XmlDataDocument();
                if (OriginalXML != "")
                {
                    xmlDoc.LoadXml(OriginalXML);
                }
                string outerXml = "<genxml>";
                outerXml = outerXml + "<textbox>";
                try
                {
                    enumerator2 = collection8.GetEnumerator();
                    while (enumerator2.MoveNext())
                    {
                        TextBox box2 = (TextBox) enumerator2.Current;
                        if (OriginalXML != "")
                        {
                            ReplaceXMLNode(xmlDoc, "genxml/textbox/" + box2.ID.ToLower(), FormatToSave(box2.Text, TypeCode.String, "en-GB"), true);
                        }
                        else
                        {
                            string str3 = "";
                            if (box2.Attributes["datatype"] != null)
                            {
                                str3 = box2.Attributes["datatype"];
                            }
                            if (str3.ToLower() == "double")
                            {
                                outerXml = outerXml + "<" + box2.ID.ToLower() + " datatype=\"" + str3.ToLower() + "\"><![CDATA[";
                                outerXml = outerXml + FormatToSave(box2.Text, TypeCode.Double, "en-GB");
                            }
                            else if (str3.ToLower() == "date")
                            {
                                outerXml = outerXml + "<" + box2.ID.ToLower() + " datatype=\"" + str3.ToLower() + "\"><![CDATA[";
                                outerXml = outerXml + FormatToSave(box2.Text, TypeCode.DateTime, "en-GB");
                            }
                            else
                            {
                                outerXml = outerXml + "<" + box2.ID.ToLower() + "><![CDATA[";
                                outerXml = outerXml + box2.Text;
                            }
                            outerXml = outerXml + "]]></" + box2.ID.ToLower() + ">";
                        }
                    }
                }
                finally
                {
                    if (enumerator2 is IDisposable)
                    {
                        (enumerator2 as IDisposable).Dispose();
                    }
                }
                outerXml = outerXml + "</textbox>" + "<checkbox>";
                try
                {
                    enumerator3 = collection.GetEnumerator();
                    while (enumerator3.MoveNext())
                    {
                        CheckBox box = (CheckBox) enumerator3.Current;
                        if (OriginalXML != "")
                        {
                            ReplaceXMLNode(xmlDoc, "genxml/checkbox/" + box.ID.ToLower(), box.Checked.ToString(), true);
                        }
                        else
                        {
                            outerXml = outerXml + "<" + box.ID.ToLower() + "><![CDATA[";
                            outerXml = outerXml + box.Checked.ToString();
                            outerXml = outerXml + "]]></" + box.ID.ToLower() + ">";
                        }
                    }
                }
                finally
                {
                    if (enumerator3 is IDisposable)
                    {
                        (enumerator3 as IDisposable).Dispose();
                    }
                }
                outerXml = outerXml + "</checkbox>" + "<dropdownlist>";
                try
                {
                    enumerator4 = collection3.GetEnumerator();
                    while (enumerator4.MoveNext())
                    {
                        DropDownList list2 = (DropDownList) enumerator4.Current;
                        if (OriginalXML != "")
                        {
                            ReplaceXMLNode(xmlDoc, "genxml/dropdownlist/" + list2.ID.ToLower(), FormatToSave(list2.SelectedValue, TypeCode.String, "en-GB"), true);
                        }
                        else
                        {
                            string str4 = "";
                            if (list2.Attributes["datatype"] != null)
                            {
                                str4 = list2.Attributes["datatype"];
                            }
                            if (str4.ToLower() == "double")
                            {
                                outerXml = outerXml + "<" + list2.ID.ToLower() + " datatype=\"" + str4.ToLower() + "\"><![CDATA[";
                                outerXml = outerXml + FormatToSave(list2.SelectedValue, TypeCode.Double, "en-GB");
                            }
                            else if (str4.ToLower() == "date")
                            {
                                outerXml = outerXml + "<" + list2.ID.ToLower() + " datatype=\"" + str4.ToLower() + "\"><![CDATA[";
                                outerXml = outerXml + FormatToSave(list2.SelectedValue, TypeCode.DateTime, "en-GB");
                            }
                            else
                            {
                                outerXml = outerXml + "<" + list2.ID.ToLower() + "><![CDATA[";
                                outerXml = outerXml + list2.SelectedValue;
                            }
                            outerXml = outerXml + "]]></" + list2.ID.ToLower() + ">";
                        }
                    }
                }
                finally
                {
                    if (enumerator4 is IDisposable)
                    {
                        (enumerator4 as IDisposable).Dispose();
                    }
                }
                outerXml = outerXml + "</dropdownlist>" + "<checkboxlist>";
                try
                {
                    enumerator5 = collection2.GetEnumerator();
                    while (enumerator5.MoveNext())
                    {
                        IEnumerator enumerator6;
                        CheckBoxList list = (CheckBoxList) enumerator5.Current;
                        string str5 = "";
                        if (list.Attributes["datatype"] != null)
                        {
                            str5 = list.Attributes["datatype"];
                        }
                        if (str5.ToLower() == "double")
                        {
                            outerXml = outerXml + "<" + list.ID.ToLower() + " datatype=\"" + str5.ToLower() + "\">";
                        }
                        else if (str5.ToLower() == "date")
                        {
                            outerXml = outerXml + "<" + list.ID.ToLower() + " datatype=\"" + str5.ToLower() + "\">";
                        }
                        else
                        {
                            outerXml = outerXml + "<" + list.ID.ToLower() + ">";
                        }
                        try
                        {
                            enumerator6 = list.Items.GetEnumerator();
                            while (enumerator6.MoveNext())
                            {
                                ListItem item2 = (ListItem) enumerator6.Current;
                                if (OriginalXML != "")
                                {
                                    ReplaceXMLatt(xmlDoc, "genxml/checkboxlist/" + list.ID.ToLower() + "/chk[.='" + FormatToSave(item2.Text, TypeCode.String, "en-GB") + "']", Conversions.ToString(item2.Selected));
                                }
                                else
                                {
                                    outerXml = outerXml + "<chk value=\"" + Conversions.ToString(item2.Selected) + "\">";
                                    if (str5.ToLower() == "double")
                                    {
                                        outerXml = outerXml + "<![CDATA[" + FormatToSave(item2.Text, TypeCode.Double, "en-GB") + "]]>";
                                    }
                                    else if (str5.ToLower() == "date")
                                    {
                                        outerXml = outerXml + "<![CDATA[" + FormatToSave(item2.Text, TypeCode.DateTime, "en-GB") + "]]>";
                                    }
                                    else
                                    {
                                        outerXml = outerXml + "<![CDATA[" + item2.Text + "]]>";
                                    }
                                    outerXml = outerXml + "</chk>";
                                }
                            }
                        }
                        finally
                        {
                            if (enumerator6 is IDisposable)
                            {
                                (enumerator6 as IDisposable).Dispose();
                            }
                        }
                        outerXml = outerXml + "</" + list.ID.ToLower() + ">";
                    }
                }
                finally
                {
                    if (enumerator5 is IDisposable)
                    {
                        (enumerator5 as IDisposable).Dispose();
                    }
                }
                outerXml = outerXml + "</checkboxlist>" + "<radiobuttonlist>";
                try
                {
                    enumerator7 = collection6.GetEnumerator();
                    while (enumerator7.MoveNext())
                    {
                        RadioButtonList list3 = (RadioButtonList) enumerator7.Current;
                        if (OriginalXML != "")
                        {
                            ReplaceXMLNode(xmlDoc, "genxml/radiobuttonlist/" + list3.ID.ToLower(), FormatToSave(list3.SelectedValue, TypeCode.String, "en-GB"), true);
                        }
                        else
                        {
                            string str6 = "";
                            if (list3.Attributes["datatype"] != null)
                            {
                                str6 = list3.Attributes["datatype"];
                            }
                            if (str6.ToLower() == "double")
                            {
                                outerXml = outerXml + "<" + list3.ID.ToLower() + " datatype=\"" + str6.ToLower() + "\"><![CDATA[";
                                outerXml = outerXml + FormatToSave(list3.SelectedValue, TypeCode.Double, "en-GB");
                            }
                            else if (str6.ToLower() == "date")
                            {
                                outerXml = outerXml + "<" + list3.ID.ToLower() + " datatype=\"" + str6.ToLower() + "\"><![CDATA[";
                                outerXml = outerXml + FormatToSave(list3.SelectedValue, TypeCode.DateTime, "en-GB");
                            }
                            else
                            {
                                outerXml = outerXml + "<" + list3.ID.ToLower() + "><![CDATA[";
                                outerXml = outerXml + list3.SelectedValue;
                            }
                            outerXml = outerXml + "]]></" + list3.ID.ToLower() + ">";
                        }
                    }
                }
                finally
                {
                    if (enumerator7 is IDisposable)
                    {
                        (enumerator7 as IDisposable).Dispose();
                    }
                }
                outerXml = outerXml + "</radiobuttonlist>" + "<edt>";
                try
                {
                    enumerator8 = collection7.GetEnumerator();
                    while (enumerator8.MoveNext())
                    {
                        GenTextEditor editor = (GenTextEditor) enumerator8.Current;
                        TextEditor editor2 = (TextEditor) editor.Controls[0];
                        if (OriginalXML != "")
                        {
                            ReplaceXMLNode(xmlDoc, "genxml/edt/" + editor2.ID.ToLower(), editor2.Text, true);
                        }
                        else
                        {
                            outerXml = outerXml + "<" + editor2.ID.ToLower() + "><![CDATA[";
                            try
                            {
                                outerXml = outerXml + editor2.Text;
                            }
                            catch (Exception exception1)
                            {
                                ProjectData.SetProjectError(exception1);
                                Exception exception = exception1;
                                ProjectData.ClearProjectError();
                            }
                            outerXml = outerXml + "]]></" + editor2.ID.ToLower() + ">";
                        }
                    }
                }
                finally
                {
                    if (enumerator8 is IDisposable)
                    {
                        (enumerator8 as IDisposable).Dispose();
                    }
                }
                outerXml = outerXml + "</edt>" + "</genxml>";
                if (OriginalXML != "")
                {
                    outerXml = xmlDoc.OuterXml;
                }
                return outerXml;
            }
            return "";
        }

        public static XmlNode getGenXMLnode(string DataXML, string XPath)
        {
            XmlNode node;
            XmlDocument document = new XmlDocument();
            try
            {
                document.LoadXml(DataXML);
                node = document.SelectSingleNode(XPath.ToLower());
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                node = null;
                ProjectData.ClearProjectError();
            }
            return node;
        }

        public static XmlNode getGenXMLnode(string ctrlID, string CtrlType, string DataXML)
        {
            if (((ctrlID == null) | (CtrlType == null)) | (DataXML == null))
            {
                return null;
            }
            return getGenXMLnode(DataXML, "genxml/" + CtrlType + "/" + ctrlID.ToLower());
        }

        public static string getGenXMLvalue(string DataXML, string XPath)
        {
            XmlNode node = getGenXMLnode(DataXML, XPath);
            if (node == null)
            {
                return "";
            }
            if (node.Attributes["datatype"] != null)
            {
                switch (node.Attributes["datatype"].InnerText.ToLower())
                {
                    case "double":
                        return FormatFromSave(node.InnerText, TypeCode.Double, "en-GB");

                    case "date":
                        return FormatFromSave(node.InnerText, TypeCode.DateTime, "en-GB");

                    case "html":
                        return node.InnerXml;
                }
                return node.InnerText;
            }
            return node.InnerText;
        }

        public static string getGridViewValue(GridViewRow row, string CtrlID)
        {
            string str2 = "";
            Control control = row.FindControl(CtrlID);
            if (control is TextBox)
            {
                return ((TextBox) control).Text;
            }
            if (control is CheckBox)
            {
                return ((CheckBox) control).Checked.ToString();
            }
            if (control is DropDownList)
            {
                return ((DropDownList) control).SelectedValue;
            }
            if (control is HiddenField)
            {
                str2 = ((HiddenField) control).Value;
            }
            return str2;
        }

        public static bool getGridViewValueBool(GridViewRow row, string CtrlID)
        {
            return Conversions.ToBoolean(getGridViewValue(row, CtrlID));
        }

        public static DateTime getGridViewValueDate(GridViewRow row, string CtrlID)
        {
            string expression = "";
            expression = getGridViewValue(row, CtrlID);
            if (Information.IsDate(expression))
            {
                return Conversions.ToDate(expression);
            }
            return Null.NullDate;
        }

        public static double getGridViewValueDbl(GridViewRow row, string CtrlID)
        {
            string expression = "";
            expression = getGridViewValue(row, CtrlID);
            if (Versioned.IsNumeric(expression))
            {
                return Conversions.ToDouble(expression);
            }
            return 0.0;
        }

        public static int getGridViewValueInt(GridViewRow row, string CtrlID)
        {
            string expression = "";
            expression = getGridViewValue(row, CtrlID);
            if (Versioned.IsNumeric(expression))
            {
                return Conversions.ToInteger(expression);
            }
            return 0;
        }

        public static bool GetHostSettingAsBoolean(string key, bool defaultValue)
        {
            bool flag2;
            try
            {
                string hostSetting = HostSettings.GetHostSetting(key);
                if (string.IsNullOrEmpty(hostSetting))
                {
                    return defaultValue;
                }
                flag2 = hostSetting.ToUpperInvariant().StartsWith("Y") || (hostSetting.ToUpperInvariant() == "TRUE");
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                ProjectData.ClearProjectError();
            }
            return flag2;
        }

        public static Hashtable getImageFileNamesInDB(int PortalID)
        {
            IEnumerator enumerator;
            IEnumerator enumerator2;
            Hashtable hashtable2 = new Hashtable();
            ProductController controller2 = new ProductController();
            NB_Store_ProductImageInfo current = new NB_Store_ProductImageInfo();
            CategoryController controller = new CategoryController();
            NB_Store_CategoriesInfo info = new NB_Store_CategoriesInfo();
            ArrayList productImageExportList = controller2.GetProductImageExportList(PortalID);
            try
            {
                enumerator = productImageExportList.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    current = (NB_Store_ProductImageInfo) enumerator.Current;
                    if (!hashtable2.ContainsKey(Path.GetFileName(current.ImagePath)))
                    {
                        hashtable2.Add(Path.GetFileName(current.ImagePath), Path.GetFileName(current.ImagePath));
                    }
                }
            }
            finally
            {
                if (enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
            productImageExportList = controller.GetCategories(PortalID, GetCurrentCulture());
            try
            {
                enumerator2 = productImageExportList.GetEnumerator();
                while (enumerator2.MoveNext())
                {
                    info = (NB_Store_CategoriesInfo) enumerator2.Current;
                    if (!hashtable2.ContainsKey(Path.GetFileName(info.ImageURL)))
                    {
                        hashtable2.Add(Path.GetFileName(info.ImageURL), Path.GetFileName(info.ImageURL));
                    }
                }
            }
            finally
            {
                if (enumerator2 is IDisposable)
                {
                    (enumerator2 as IDisposable).Dispose();
                }
            }
            return hashtable2;
        }

        public static object getLangCache(int PortalID, string CacheKey, string Lang)
        {
            return DataCache.GetCache(Lang.ToLower() + CacheKey.ToLower() + PortalID.ToString());
        }

        public static string GetMerchantCountryCode(int PortalID)
        {
            return Strings.Right(GetMerchantCulture(PortalID), 2);
        }

        public static string GetMerchantCulture(int PortalID)
        {
            NB_Store_SettingsInfo info = new SettingsController().GetSetting(PortalID, "merchant.culture", "None");
            if (info == null)
            {
                return GetCurrentCulture();
            }
            return info.SettingValue;
        }

        public static string GetMerchantEmail(int PortalID)
        {
            SettingsController controller = new SettingsController();
            NB_Store_SettingsInfo info = controller.GetSetting(PortalID, "merchant.email", "None");
            if (info == null)
            {
                info = controller.GetSetting(PortalID, "store.email", "None");
                if (info == null)
                {
                    return "";
                }
                return info.SettingValue;
            }
            return info.SettingValue;
        }

        public static string GetMsgText(string PortalId, string TextTemplateID, string DefaultMsg)
        {
            SettingsController controller = new SettingsController();
            string str2 = DefaultMsg;
            NB_Store_SettingsTextInfo info = controller.GetSettingsText(Conversions.ToInteger(PortalId), TextTemplateID, GetCurrentCulture());
            if (info != null)
            {
                if (info.SettingText == "")
                {
                    return str2;
                }
                str2 = Strings.Replace(Strings.Replace(Strings.Replace(Strings.Replace(info.SettingText, "[TAG:Login]", "javascript:__doPostBack('dnn$dnnLOGIN$cmdLogin','')", 1, -1, CompareMethod.Binary), "[TAG:Register]", "javascript:__doPostBack('dnn$dnnUSER$cmdRegister','')", 1, -1, CompareMethod.Binary), "[TAG:SkipLogin]", DotNetNuke.Common.Globals.NavigateURL("", new string[] { "stg=2", "logmsg=0" }), 1, -1, CompareMethod.Binary), "[TAG:STOREEMAIL]", GetStoreEmail(Conversions.ToInteger(PortalId)), 1, -1, CompareMethod.Binary);
                if (Strings.InStr(str2, "[", CompareMethod.Binary) > 0)
                {
                    str2 = new TokenStoreReplace(Conversions.ToInteger(PortalId), GetCurrentCulture()).DoTokenReplace(str2);
                }
            }
            return str2;
        }

        public static OptCodeInfo GetOptCodeInfo(int PortalID, string OptCode, UserInfo UserInfo)
        {
            return GetOptCodeInfo(PortalID, OptCode, UserInfo, "", "");
        }

        public static OptCodeInfo GetOptCodeInfo(int PortalID, string OptCode, UserInfo UserInfo, string TextOptions, string TextOptionsXML)
        {
            ProductController controller = new ProductController();
            OptCodeInfo info5 = null;
            PromoController controller2 = new PromoController();
            string str = GetStoreSettingText(PortalID, "optionseperator.text", GetCurrentCulture(), false, true);
            if (str == "")
            {
                str = "/";
            }
            if (CalcCartInterface.Instance() != null)
            {
                info5 = CalcCartInterface.Instance().GetOptCodeInfo(PortalID, OptCode, UserInfo, TextOptions, TextOptionsXML);
            }
            if (info5 == null)
            {
                info5 = new OptCodeInfo {
                    ItemDesc = "",
                    UnitCost = decimal.Zero,
                    OptCode = ""
                };
                string[] strArray = OptCode.Split(new char[] { '-' });
                int upperBound = strArray.GetUpperBound(0);
                for (int i = 0; i <= upperBound; i++)
                {
                    if (Versioned.IsNumeric(strArray[i]))
                    {
                        OptCodeInfo info6;
                        if (i == 0)
                        {
                            NB_Store_ModelInfo model = controller.GetModel(Conversions.ToInteger(strArray[i]), GetCurrentCulture());
                            if (model != null)
                            {
                                NB_Store_ProductsInfo product = controller.GetProduct(model.ProductID, GetCurrentCulture());
                                if (product == null)
                                {
                                    info5.ItemDesc = model.ModelName + ".";
                                }
                                else
                                {
                                    info5.ItemDesc = product.ProductName + " " + Strings.Replace(model.ModelName, product.ProductName, "", 1, -1, CompareMethod.Binary) + "." + model.ModelRef + ".";
                                    info5.ItemDesc = Strings.Trim(info5.ItemDesc);
                                }
                                info5.UnitCost = decimal.Add(info5.UnitCost, model.UnitCost);
                                double num2 = Convert.ToDouble(controller2.GetSalePrice(model, UserInfo));
                                if (IsDealer(model.PortalID, UserInfo, GetCurrentCulture()))
                                {
                                    if (decimal.Compare(model.DealerCost, decimal.Zero) > 0)
                                    {
                                        if ((num2 > -1.0) & (num2 < Convert.ToDouble(model.DealerCost)))
                                        {
                                            info5.Discount = new decimal(num2 - Convert.ToDouble(info5.UnitCost));
                                        }
                                        else
                                        {
                                            info5.Discount = decimal.Subtract(model.DealerCost, info5.UnitCost);
                                        }
                                    }
                                    else if (num2 > -1.0)
                                    {
                                        info5.Discount = new decimal(num2 - Convert.ToDouble(info5.UnitCost));
                                    }
                                    else
                                    {
                                        info5.Discount = decimal.Zero;
                                    }
                                }
                                else if (num2 > -1.0)
                                {
                                    info5.Discount = new decimal(num2 - Convert.ToDouble(info5.UnitCost));
                                }
                                else
                                {
                                    info5.Discount = decimal.Zero;
                                }
                                info6 = info5;
                                info6.OptCode = info6.OptCode + strArray[i] + "-";
                            }
                        }
                        else
                        {
                            if (i == 1)
                            {
                                info5.ItemDesc = info5.ItemDesc.TrimEnd(new char[] { '.' }) + str;
                            }
                            NB_Store_OptionValueInfo optionValue = controller.GetOptionValue(Conversions.ToInteger(strArray[i]), GetCurrentCulture());
                            if (optionValue != null)
                            {
                                info5.UnitCost = decimal.Add(info5.UnitCost, optionValue.AddedCost);
                                info6 = info5;
                                info6.ItemDesc = info6.ItemDesc + optionValue.OptionValueDesc + str;
                                info6 = info5;
                                info6.OptCode = info6.OptCode + strArray[i] + "-";
                            }
                        }
                    }
                }
                info5.ItemDesc = info5.ItemDesc.TrimEnd(new char[] { '.' });
                if (info5.ItemDesc.EndsWith(str))
                {
                    info5.ItemDesc = info5.ItemDesc.Substring(0, info5.ItemDesc.Length - str.Length);
                }
                info5.OptCode = info5.OptCode.TrimEnd(new char[] { '-' });
                if (TextOptions == "")
                {
                    if (info5.ItemDesc.EndsWith(str))
                    {
                        info5.ItemDesc = info5.ItemDesc.Substring(0, info5.ItemDesc.Length - str.Length);
                    }
                    return info5;
                }
                info5.ItemDesc = info5.ItemDesc + str + TextOptions;
            }
            return info5;
        }

        public static string GetProductListUrlByCatID(int PortalID, int TabID, int CatID, string SEOName, string Lang)
        {
            if (SEOName != "")
            {
                SEOName = Strings.Replace(SEOName, " ", "_", 1, -1, CompareMethod.Binary);
                SEOName = Regex.Replace(SEOName, @"[\W]", "");
            }
            if (CatID == -1)
            {
                if (GetHostSettingAsBoolean("UseFriendlyUrls", false) & (SEOName != ""))
                {
                    return GetSEOLink(PortalID, TabID, "", SEOName + ".aspx", new string[] { "Language=" + Lang });
                }
                PortalSettings settings = PortalController.GetCurrentPortalSettings();
                return DotNetNuke.Common.Globals.NavigateURL(TabID, false, settings, "", Lang, new string[0]);
            }
            if (GetHostSettingAsBoolean("UseFriendlyUrls", false) & (SEOName != ""))
            {
                return GetSEOLink(PortalID, TabID, "", SEOName + ".aspx", new string[] { "CatID=" + CatID.ToString(), "Language=" + Lang });
            }
            PortalSettings currentPortalSettings = PortalController.GetCurrentPortalSettings();
            return DotNetNuke.Common.Globals.NavigateURL(TabID, false, currentPortalSettings, "", Lang, new string[] { "CatID=" + Conversions.ToString(CatID) });
        }

        public static ProductStockLevels getProductStockLevels(DataListItem container)
        {
            return getProductStockLevels(PortalController.GetCurrentPortalSettings().PortalId, container);
        }

        public static ProductStockLevels getProductStockLevels(int PortalID, DataListItem container)
        {
            ProductStockLevels levels2 = new ProductStockLevels();
            int num = 0;
            int num2 = Conversions.ToInteger(DataBinder.Eval(RuntimeHelpers.GetObjectValue(container.DataItem), "QtyRemaining"));
            int num3 = Conversions.ToInteger(DataBinder.Eval(RuntimeHelpers.GetObjectValue(container.DataItem), "QtyStockSet"));
            bool storeSettingBoolean = GetStoreSettingBoolean(PortalID, "lockstockoncart");
            if (num2 >= 0)
            {
                levels2.StockOn = true;
                levels2.Qty = num2;
                levels2.MaxQty = num3;
                if (storeSettingBoolean)
                {
                    IEnumerator enumerator;
                    CartController controller = new CartController();
                    ProductController controller2 = new ProductController();
                    int productID = Conversions.ToInteger(DataBinder.Eval(RuntimeHelpers.GetObjectValue(container.DataItem), "ProductID"));
                    string lang = Conversions.ToString(DataBinder.Eval(RuntimeHelpers.GetObjectValue(container.DataItem), "Lang"));
                    ArrayList list = controller2.GetModelList(PortalID, productID, lang, true);
                    try
                    {
                        enumerator = list.GetEnumerator();
                        while (enumerator.MoveNext())
                        {
                            NB_Store_ModelInfo current = (NB_Store_ModelInfo) enumerator.Current;
                            if (current.QtyRemaining >= 0)
                            {
                                num += controller.GetCartModelQty(PortalID, current.ModelID, "");
                            }
                        }
                    }
                    finally
                    {
                        if (enumerator is IDisposable)
                        {
                            (enumerator as IDisposable).Dispose();
                        }
                    }
                    levels2.CartQty = num;
                }
                if ((levels2.MaxQty > 0) & (levels2.Qty > 0))
                {
                    levels2.Percent = (int) Math.Round((double) ((100.0 / ((double) levels2.MaxQty)) * (levels2.Qty - levels2.CartQty)));
                    if (levels2.Percent < 0)
                    {
                        levels2.Percent = 0;
                    }
                    if ((levels2.Percent == 0) & ((levels2.Qty - levels2.CartQty) > 0))
                    {
                        levels2.Percent = 1;
                    }
                    levels2.PercentActual = (int) Math.Round((double) ((100.0 / ((double) levels2.MaxQty)) * levels2.Qty));
                    levels2.PercentSold = 100 - ((int) Math.Round((double) ((100.0 / ((double) levels2.MaxQty)) * levels2.Qty)));
                    if (levels2.PercentSold == 100)
                    {
                        levels2.PercentSold = 0x63;
                    }
                    levels2.PercentInProgess = 100 - (levels2.Percent + levels2.PercentSold);
                    return levels2;
                }
                levels2.PercentSold = 100;
                levels2.PercentInProgess = 0;
                levels2.PercentActual = 0;
                levels2.Percent = 0;
            }
            return levels2;
        }

        public static string GetProductUrl(int PortalID, int TabID, NB_Store_ProductsInfo objPInfo, int CatID, bool CanonicalLink)
        {
            string expression = GetStoreSetting(PortalID, "urlname.column", "None");
            try
            {
                if (expression != "")
                {
                    expression = Conversions.ToString(DataBinder.Eval(objPInfo, expression));
                }
                else
                {
                    expression = objPInfo.SEOName;
                }
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                expression = "";
                ProjectData.ClearProjectError();
            }
            return GetProductUrlByProductID(PortalID, TabID, objPInfo.ProductID, CatID, expression, CanonicalLink, objPInfo.Lang);
        }

        public static string GetProductUrl(int PortalID, int TabID, ProductListInfo objPInfo, int CatID, bool CanonicalLink)
        {
            string expression = GetStoreSetting(PortalID, "urlname.column", "None");
            try
            {
                if (expression != "")
                {
                    expression = Conversions.ToString(DataBinder.Eval(objPInfo, expression));
                }
                else
                {
                    expression = objPInfo.SEOName;
                }
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                expression = "";
                ProjectData.ClearProjectError();
            }
            return GetProductUrlByProductID(PortalID, TabID, objPInfo.ProductID, CatID, expression, CanonicalLink, objPInfo.Lang);
        }

        public static string GetProductUrlByProductID(int PortalID, int TabID, int ProductID, int CatID, string SEOName, bool CanonicalLink, string Lang)
        {
            if (SEOName != "")
            {
                SEOName = Strings.Replace(SEOName, " ", "_", 1, -1, CompareMethod.Binary);
                SEOName = Regex.Replace(SEOName, @"[\W]", "");
            }
            if (CanonicalLink | (CatID == -1))
            {
                if (GetHostSettingAsBoolean("UseFriendlyUrls", false) & (SEOName != ""))
                {
                    return GetSEOLink(PortalID, TabID, "", SEOName + ".aspx", new string[] { "ProdID=" + ProductID.ToString(), "Language=" + Lang });
                }
                PortalSettings settings = PortalController.GetCurrentPortalSettings();
                return DotNetNuke.Common.Globals.NavigateURL(TabID, false, settings, "", Lang, new string[] { "ProdID=" + ProductID.ToString() });
            }
            if (GetHostSettingAsBoolean("UseFriendlyUrls", false) & (SEOName != ""))
            {
                return GetSEOLink(PortalID, TabID, "", SEOName + ".aspx", new string[] { "ProdID=" + ProductID.ToString(), "Language=" + Lang, "CatID=" + Conversions.ToString(CatID) });
            }
            PortalSettings currentPortalSettings = PortalController.GetCurrentPortalSettings();
            return DotNetNuke.Common.Globals.NavigateURL(TabID, false, currentPortalSettings, "", Lang, new string[] { "ProdID=" + ProductID.ToString(), "CatID=" + Conversions.ToString(CatID) });
        }

        public static string getRSSItem(ProductListInfo objInfo, string StoreTabID)
        {
            string expression = "";
            TokenStoreReplace replace = new TokenStoreReplace(objInfo);
            PortalSettings currentPortalSettings = PortalController.GetCurrentPortalSettings();
            expression = Strings.Replace(Strings.Replace(GetStoreSettingText(objInfo.PortalID, "rssitem.template", objInfo.Lang, false, true), "<![CDATA[", "**CDATASTART**", 1, -1, CompareMethod.Binary), "]]>", "**CDATAEND**", 1, -1, CompareMethod.Binary);
            if (!Versioned.IsNumeric(StoreTabID))
            {
                StoreTabID = GetStoreSetting(objInfo.PortalID, "store.tab", objInfo.Lang);
            }
            if (Versioned.IsNumeric(StoreTabID))
            {
                expression = Strings.Replace(expression, "[Product:Link]", DotNetNuke.Common.Globals.ResolveUrl(GetProductUrl(objInfo.PortalID, Conversions.ToInteger(StoreTabID), objInfo, -1, true)), 1, -1, CompareMethod.Binary);
            }
            else
            {
                expression = Strings.Replace(expression, "[Product:Link]", "NO STORE TABID", 1, -1, CompareMethod.Binary);
            }
            return Strings.Replace(Strings.Replace(replace.DoTokenReplace(expression), "**CDATASTART**", "<![CDATA[", 1, -1, CompareMethod.Binary), "**CDATAEND**", "]]>", 1, -1, CompareMethod.Binary);
        }

        public static string getRSSoutput(ArrayList aryList, string StoreTabID)
        {
            IEnumerator enumerator;
            string replacement = "";
            string expression = "";
            expression = GetStoreSettingText(PortalController.GetCurrentPortalSettings().PortalId, "rss.template", GetCurrentCulture(), false, true);
            try
            {
                enumerator = aryList.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    ProductListInfo current = (ProductListInfo) enumerator.Current;
                    replacement = replacement + getRSSItem(current, StoreTabID);
                }
            }
            finally
            {
                if (enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
            return Strings.Replace(expression, "[Product:rssitem]", replacement, 1, -1, CompareMethod.Binary);
        }

        public static string GetSEOLink(int PortalId, int TabID, string ControlKey, string Title, params string[] AdditionalParameters)
        {
            DotNetNuke.Entities.Tabs.TabInfo tab = new TabController().GetTab(TabID, PortalId, false);
            LocaleCollection validLocales = GetValidLocales();
            if (tab != null)
            {
                string path = "~/default.aspx?tabid=" + Conversions.ToString(tab.TabID);
                foreach (string str3 in AdditionalParameters)
                {
                    if (validLocales.Count > 1)
                    {
                        path = path + "&" + str3;
                    }
                    else if (!str3.ToLower().StartsWith("language"))
                    {
                        path = path + "&" + str3;
                    }
                }
                if (string.IsNullOrEmpty(Title))
                {
                    Title = "Default.aspx";
                }
                return DotNetNuke.Common.Globals.FriendlyUrl(tab, path, Title);
            }
            return "";
        }

        public static string getSettingName(int Portalid, string SettingName, UserInfo UserInfo)
        {
            if (EventInterface.Instance() != null)
            {
                SettingName = EventInterface.Instance().getSettingName(Portalid, SettingName, UserInfo);
            }
            return SettingName;
        }

        public static string getSettingTextName(int Portalid, string SettingName, UserInfo UserInfo)
        {
            if (EventInterface.Instance() != null)
            {
                SettingName = EventInterface.Instance().getSettingTextName(Portalid, SettingName, UserInfo);
            }
            return SettingName;
        }

        public static Hashtable getStatusList(string Lang)
        {
            IEnumerator enumerator;
            OrderController controller = new OrderController();
            Hashtable hashtable2 = new Hashtable();
            ArrayList orderStatusList = controller.GetOrderStatusList(Lang);
            try
            {
                enumerator = orderStatusList.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    NB_Store_OrderStatusInfo current = (NB_Store_OrderStatusInfo) enumerator.Current;
                    hashtable2.Add(current.OrderStatusID, current.OrderStatusText);
                }
            }
            finally
            {
                if (enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
            return hashtable2;
        }

        public static HttpCookie getStoreCookie(int PortalID, string CookieName)
        {
            string name = "NB_Store2_" + CookieName + "_Portal" + PortalID.ToString();
            HttpCookie cookie = HttpContext.Current.Request.Cookies[name];
            if (cookie == null)
            {
                cookie = new HttpCookie(name);
            }
            return cookie;
        }

        public static string getStoreCookieValue(int PortalID, string CookieName, string ValueID)
        {
            string str = "NB_Store2_" + CookieName + "_Portal" + PortalID.ToString();
            HttpCookie objCookie = HttpContext.Current.Request.Cookies[str];
            return getStoreCookieValue(PortalID, objCookie, ValueID);
        }

        public static string getStoreCookieValue(int PortalID, HttpCookie objCookie, string ValueID)
        {
            if (objCookie != null)
            {
                if (objCookie[ValueID] != null)
                {
                    return StoreDecrypt(PortalID, objCookie[ValueID]);
                }
                return "";
            }
            return "";
        }

        public static string GetStoreEmail(int PortalID)
        {
            SettingsController controller = new SettingsController();
            NB_Store_SettingsInfo info = controller.GetSetting(PortalID, "store.email", "None");
            if (info == null)
            {
                info = controller.GetSetting(PortalID, "merchant.email", "None");
                if (info == null)
                {
                    return "";
                }
                return info.SettingValue;
            }
            return info.SettingValue;
        }

        public static string GetStoreSetting(int Portalid, string SettingName)
        {
            return GetStoreSetting(Portalid, SettingName, "None", false);
        }

        public static string GetStoreSetting(int Portalid, string SettingName, string Lang)
        {
            return GetStoreSetting(Portalid, SettingName, Lang, false);
        }

        public static string GetStoreSetting(int Portalid, string SettingName, string Lang, UserInfo UserInfo)
        {
            SettingName = getSettingName(Portalid, SettingName, UserInfo);
            return GetStoreSetting(Portalid, SettingName, Lang, false);
        }

        public static string GetStoreSetting(int Portalid, string SettingName, string Lang, bool NotCached)
        {
            NB_Store_SettingsInfo info;
            SettingsController controller = new SettingsController();
            if (NotCached)
            {
                info = controller.GetSettingNotCached(Portalid, SettingName, Lang);
            }
            else
            {
                info = controller.GetSetting(Portalid, SettingName, Lang);
            }
            if (info == null)
            {
                return "";
            }
            return info.SettingValue;
        }

        public static bool GetStoreSettingBoolean(int Portalid, string SettingName)
        {
            return GetStoreSettingBoolean(Portalid, SettingName, "None");
        }

        public static bool GetStoreSettingBoolean(int Portalid, string SettingName, string Lang)
        {
            bool flag;
            try
            {
                flag = Conversions.ToBoolean(GetStoreSetting(Portalid, SettingName, Lang, false));
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                flag = false;
                ProjectData.ClearProjectError();
            }
            return flag;
        }

        public static int GetStoreSettingInt(int Portalid, string SettingName, string Lang)
        {
            string expression = GetStoreSetting(Portalid, SettingName, Lang, false);
            if (Versioned.IsNumeric(expression))
            {
                return Conversions.ToInteger(expression);
            }
            return 0;
        }

        public static string GetStoreSettingText(int Portalid, string SettingName, string Lang)
        {
            return GetStoreSettingText(Portalid, SettingName, Lang, false);
        }

        public static string GetStoreSettingText(int Portalid, string SettingName, string Lang, UserInfo UserInfo)
        {
            SettingName = getSettingTextName(Portalid, SettingName, UserInfo);
            return GetStoreSettingText(Portalid, SettingName, Lang, false);
        }

        public static string GetStoreSettingText(int Portalid, string SettingName, string Lang, bool NotCached)
        {
            NB_Store_SettingsTextInfo info;
            SettingsController controller = new SettingsController();
            if (NotCached)
            {
                info = controller.GetSettingsTextNotCached(Portalid, SettingName, Lang);
            }
            else
            {
                info = controller.GetSettingsText(Portalid, SettingName, Lang);
            }
            if (info == null)
            {
                return "";
            }
            return info.SettingValue;
        }

        public static string GetStoreSettingText(int Portalid, string SettingName, string Lang, bool NotCached, bool HtmlDecode)
        {
            if (HtmlDecode)
            {
                return HttpUtility.HtmlDecode(GetStoreSettingText(Portalid, SettingName, Lang, NotCached));
            }
            return GetStoreSettingText(Portalid, SettingName, Lang, NotCached);
        }

        public static XmlNode getTokenPropXMLnode(string TagXMLString)
        {
            XmlDataDocument document = new XmlDataDocument();
            string xml = HttpUtility.HtmlDecode(TagXMLString);
            xml = "<root>" + xml + "</root>";
            document.LoadXml(xml);
            return document.SelectSingleNode("root/prop");
        }

        public static Hashtable getUploadedFileNamesInDB(int PortalID)
        {
            IEnumerator enumerator;
            Hashtable hashtable2 = new Hashtable();
            ArrayList orderDetailList = new OrderController().GetOrderDetailList(-1);
            try
            {
                enumerator = orderDetailList.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    NB_Store_OrderDetailsInfo current = (NB_Store_OrderDetailsInfo) enumerator.Current;
                    try
                    {
                        IEnumerator enumerator2;
                        XmlDataDocument document = new XmlDataDocument();
                        document.LoadXml(current.CartXMLInfo);
                        XmlNodeList list2 = document.SelectNodes("root/*");
                        try
                        {
                            enumerator2 = list2.GetEnumerator();
                            while (enumerator2.MoveNext())
                            {
                                XmlNode node = (XmlNode) enumerator2.Current;
                                if (!hashtable2.ContainsKey(Path.GetFileName(node.InnerXml)) & node.Name.StartsWith("fu"))
                                {
                                    hashtable2.Add(Path.GetFileName(node.InnerXml), Path.GetFileName(node.InnerXml));
                                }
                            }
                        }
                        finally
                        {
                            if (enumerator2 is IDisposable)
                            {
                                (enumerator2 as IDisposable).Dispose();
                            }
                        }
                    }
                    catch (Exception exception1)
                    {
                        ProjectData.SetProjectError(exception1);
                        Exception exception = exception1;
                        ProjectData.ClearProjectError();
                    }
                }
            }
            finally
            {
                if (enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
            return hashtable2;
        }

        public static string[] getUrlCookieInfo(int PortalID, params string[] AdditionalParameters)
        {
            string[] strArray2 = new string[(AdditionalParameters.Length + 8) + 1];
            strArray2[0] = Conversions.ToString(getCookieURLparam(PortalID, "orderby"));
            strArray2[1] = Conversions.ToString(getCookieURLparam(PortalID, "CatID"));
            strArray2[2] = Conversions.ToString(getCookieURLparam(PortalID, "RtnTab"));
            strArray2[3] = Conversions.ToString(getCookieURLparam(PortalID, "PageIndex"));
            strArray2[4] = Conversions.ToString(getCookieURLparam(PortalID, "currentpage"));
            strArray2[5] = Conversions.ToString(getCookieURLparam(PortalID, "wishlist"));
            strArray2[6] = Conversions.ToString(getCookieURLparam(PortalID, "Search"));
            strArray2[7] = Conversions.ToString(getCookieURLparam(PortalID, "desc"));
            int num2 = AdditionalParameters.Length - 1;
            for (int i = 0; i <= num2; i++)
            {
                strArray2[i + 9] = AdditionalParameters[i];
            }
            return strArray2;
        }

        public static string getURLParam(HttpContext context, string ParamKey)
        {
            if (context.Request.QueryString[ParamKey] != null)
            {
                return context.Request.QueryString[ParamKey];
            }
            return "";
        }

        public static LocaleCollection GetValidLocales()
        {
            LocaleCollection enabledLocales = DotNetNuke.Services.Localization.Localization.GetEnabledLocales();
            if (enabledLocales.Count == 0)
            {
                enabledLocales = DotNetNuke.Services.Localization.Localization.GetSupportedLocales();
            }
            return enabledLocales;
        }

        public static string HTTPPOSTEncode(string postString)
        {
            postString = postString.Replace(@"\", "");
            postString = HttpUtility.UrlEncode(postString);
            postString = postString.Replace("%2f", "/");
            return postString;
        }

        public static void IncludeCanonicalLink(Page page, string href)
        {
            if (href != "")
            {
                HtmlLink child = new HtmlLink();
                child.Attributes.Add("rel", "canonical");
                child.Href = href;
                page.Header.Controls.Add(child);
            }
        }

        public static void IncludeScripts(int PortalID, string StoreInstallPath, Page Page, string JSIncludeKey, string JSStartUpIncludeKey, string CSSIncludeKey)
        {
            SettingsController controller = new SettingsController();
            try
            {
                NewLateBinding.LateCall(RuntimeHelpers.GetObjectValue(Activator.CreateInstance("DotNetNuke", "DotNetNuke.Framework.jQuery").Unwrap()), null, "RequestRegistration", new object[0], null, null, null, true);
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exc = exception1;
                DotNetNuke.Services.Exceptions.Exceptions.LogException(exc);
                ProjectData.ClearProjectError();
            }
            NB_Store_SettingsInfo info = controller.GetSetting(PortalID, JSIncludeKey, GetCurrentCulture());
            if ((info != null) && (info.SettingValue.Trim() != ""))
            {
                string[] strArray = info.SettingValue.Split(new char[] { ',' });
                int upperBound = strArray.GetUpperBound(0);
                for (int i = 0; i <= upperBound; i++)
                {
                    RegisterJS(strArray[i], strArray[i], StoreInstallPath, Page);
                }
            }
            info = controller.GetSetting(PortalID, JSStartUpIncludeKey, GetCurrentCulture());
            if ((info != null) && (info.SettingValue.Trim() != ""))
            {
                string[] strArray2 = info.SettingValue.Split(new char[] { ',' });
                int num5 = strArray2.GetUpperBound(0);
                for (int j = 0; j <= num5; j++)
                {
                    LoadJQueryCode(PortalID, strArray2[j], Page);
                }
            }
            info = controller.GetSetting(PortalID, CSSIncludeKey, GetCurrentCulture());
            if ((info != null) && (info.SettingValue.Trim() != ""))
            {
                string[] strArray3 = info.SettingValue.Split(new char[] { ',' });
                int num6 = strArray3.GetUpperBound(0);
                for (int k = 0; k <= num6; k++)
                {
                    if (strArray3[k].StartsWith("/"))
                    {
                        AddCSSLink(strArray3[k], Page);
                    }
                    else
                    {
                        AddCSSLink(StoreInstallPath + "js/" + strArray3[k], Page);
                    }
                }
            }
        }

        public static bool IsDealer(int PortalID, UserInfo UserInfo, string Lang)
        {
            string role = GetStoreSetting(PortalID, "dealer.role", Lang);
            return (UserInfo.IsInRole(role) & (role != ""));
        }

        public static bool IsDNN4()
        {
            int num;
            int num2;
            int num3;
            int num4;
            bool flag2 = false;
            if (SafeDNNVersion(ref num2, ref num3, ref num4, ref num) && (num2 == 4))
            {
                flag2 = true;
            }
            return flag2;
        }

        public static bool IsEditor(int Portalid, UserInfo Usrinfo)
        {
            if (Usrinfo == null)
            {
                return false;
            }
            string role = "";
            if (IsManager(Portalid, Usrinfo))
            {
                return true;
            }
            role = GetStoreSetting(Portalid, "editor.role", GetCurrentCulture());
            return Usrinfo.IsInRole(role);
        }

        public static bool IsImageFile(string strExtension)
        {
            return ((((((Strings.LCase(strExtension) == ".jpg") | (Strings.LCase(strExtension) == ".jpeg")) | (Strings.LCase(strExtension) == ".gif")) | (Strings.LCase(strExtension) == ".png")) | (Strings.LCase(strExtension) == ".tiff")) | (Strings.LCase(strExtension) == ".bmp"));
        }

        public static bool IsManager(int Portalid, UserInfo Usrinfo)
        {
            if (Usrinfo == null)
            {
                return false;
            }
            string role = "";
            string str = "";
            str = GetStoreSetting(Portalid, "managerlite.role", GetCurrentCulture());
            role = GetStoreSetting(Portalid, "manager.role", GetCurrentCulture());
            return (((Usrinfo.IsInRole("Administrators") | Usrinfo.IsInRole(role)) | Usrinfo.IsInRole(str)) | Usrinfo.IsSuperUser);
        }

        public static bool IsOnlyManagerLite(int Portalid, UserInfo Usrinfo)
        {
            if (Usrinfo != null)
            {
                string role = "";
                role = GetStoreSetting(Portalid, "managerlite.role", GetCurrentCulture());
                if (Usrinfo.IsInRole(role))
                {
                    if ((Usrinfo.IsSuperUser | Usrinfo.IsInRole("Administrator")) | Usrinfo.IsInRole(GetStoreSetting(Portalid, "manager.role", GetCurrentCulture())))
                    {
                        return false;
                    }
                    return true;
                }
            }
            return false;
        }

        public static void LoadJQueryCode(int PortalID, string SettingsKey, Page Page)
        {
            SettingsController controller = new SettingsController();
            string script = "";
            NB_Store_SettingsTextInfo info = controller.GetSettingsText(PortalID, SettingsKey, GetCurrentCulture());
            if (info != null)
            {
                if (info.SettingText.ToLower().StartsWith("jquery"))
                {
                    script = "<script language=\"javascript\" type=\"text/javascript\">" + HttpUtility.HtmlDecode(info.SettingText) + "</script>";
                }
                else
                {
                    script = HttpUtility.HtmlDecode(info.SettingText);
                }
                Page.ClientScript.RegisterStartupScript(Page.GetType(), SettingsKey, script);
            }
        }

        public static void LocalizeDDL(DropDownList ddl, string NameList)
        {
            int index = 0;
            string[] strArray = NameList.Split(new char[] { ',' });
            if (strArray.GetUpperBound(0) < ddl.Items.Count)
            {
                int upperBound = strArray.GetUpperBound(0);
                for (index = 0; index <= upperBound; index++)
                {
                    ddl.Items[index].Text = strArray[index];
                }
            }
        }

        public static Hashtable ParseGateway(string GatewayParams)
        {
            Hashtable hashtable2 = new Hashtable();
            try
            {
                IEnumerator enumerator;
                XmlDataDocument document = new XmlDataDocument();
                document.LoadXml(Strings.Trim(GatewayParams));
                XmlNodeList list = document.SelectNodes("/root/*");
                try
                {
                    enumerator = list.GetEnumerator();
                    while (enumerator.MoveNext())
                    {
                        XmlNode current = (XmlNode) enumerator.Current;
                        hashtable2.Add(current.Name, current.InnerXml);
                    }
                }
                finally
                {
                    if (enumerator is IDisposable)
                    {
                        (enumerator as IDisposable).Dispose();
                    }
                }
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                string str = "";
                string[] strArray2 = Strings.Split(GatewayParams, "\r\n", -1, CompareMethod.Binary);
                int upperBound = strArray2.GetUpperBound(0);
                for (int i = 0; i <= upperBound; i++)
                {
                    string[] strArray = Strings.Split(strArray2[i], "=", -1, CompareMethod.Binary);
                    if (strArray.GetUpperBound(0) >= 1)
                    {
                        str = "";
                        int num4 = strArray.GetUpperBound(0);
                        for (int j = 1; j <= num4; j++)
                        {
                            if (j == 1)
                            {
                                str = str + strArray[j];
                            }
                            else
                            {
                                str = str + "=" + strArray[j];
                            }
                        }
                        hashtable2.Add(strArray[0], str);
                    }
                }
                ProjectData.ClearProjectError();
            }
            return hashtable2;
        }

        public static void PopulateAvailableLanguages(DropDownList ddlLocales, HttpRequest Request)
        {
            PopulateAvailableLanguages(ddlLocales, Request, "", "");
        }

        public static void PopulateAvailableLanguages(DropDownList ddlLocales, HttpRequest Request, string DefaultSelectValue, string DefaultSelectText)
        {
            LocaleCollection validLocales = GetValidLocales();
            ddlLocales.Items.Clear();
            int num2 = validLocales.Count - 1;
            for (int i = 0; i <= num2; i++)
            {
                DictionaryEntry entry = validLocales[i];
                CultureInfo info = CultureInfo.CreateSpecificCulture(((Locale) entry.Value).Code);
                ListItem item = new ListItem();
                entry = validLocales[i];
                item.Value = ((Locale) entry.Value).Code;
                entry = validLocales[i];
                item.Text = info.NativeName + " (" + ((Locale) entry.Value).Code + ")";
                ddlLocales.Items.Add(item);
            }
            if (DefaultSelectValue != "")
            {
                ListItem item2 = new ListItem {
                    Value = DefaultSelectValue,
                    Text = DefaultSelectText
                };
                ddlLocales.Items.Insert(0, item2);
            }
            string currentCulture = GetCurrentCulture();
            if (Request["DSEditLocale"] != null)
            {
                currentCulture = Convert.ToString(Request["DSEditLocale"]);
            }
            if (ddlLocales.Items.FindByValue(currentCulture) != null)
            {
                ddlLocales.ClearSelection();
                ddlLocales.Items.FindByValue(currentCulture).Selected = true;
            }
        }

        public static int populateCategoryDualList(int PortalId, int EntryID, DualListControl dlCategories)
        {
            IEnumerator enumerator;
            IEnumerator enumerator2;
            ArrayList list = new ArrayList();
            ArrayList list4 = new ArrayList();
            CategoryController controller = new CategoryController();
            ProductController controller2 = new ProductController();
            string str = "";
            ArrayList categories = controller.GetCategories(PortalId, GetCurrentCulture());
            if (categories.Count == 0)
            {
                return 0;
            }
            ArrayList categoriesAssigned = controller2.GetCategoriesAssigned(EntryID);
            try
            {
                enumerator = categoriesAssigned.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    NB_Store_ProductCategoryInfo current = (NB_Store_ProductCategoryInfo) enumerator.Current;
                    str = str + "*" + Conversions.ToString(current.CategoryID) + ";";
                }
            }
            finally
            {
                if (enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
            ArrayList aryRtn = new ArrayList();
            BuildCategoryList(categories, 0, "", aryRtn);
            try
            {
                enumerator2 = aryRtn.GetEnumerator();
                while (enumerator2.MoveNext())
                {
                    ListItem item = (ListItem) enumerator2.Current;
                    if (str.IndexOf("*" + item.Value + ";") != -1)
                    {
                        list.Add(item);
                    }
                    else
                    {
                        list4.Add(item);
                    }
                }
            }
            finally
            {
                if (enumerator2 is IDisposable)
                {
                    (enumerator2 as IDisposable).Dispose();
                }
            }
            dlCategories.Assigned = list;
            dlCategories.Available = list4;
            return (list.Count + list4.Count);
        }

        public static void populateCategoryList(int PortalId, DropDownList ddlCategories)
        {
            populateCategoryList(PortalId, ddlCategories, "", "", "");
        }

        public static void populateCategoryList(int PortalId, DropDownList ddlCategories, string DefaultSelectValue, string DefaultSelectText, string SelectedValue)
        {
            CategoryController controller = new CategoryController();
            ddlCategories.Items.Clear();
            BuildCategoryList(controller.GetCategories(PortalId, GetCurrentCulture()), ddlCategories, 0, "");
            if (DefaultSelectValue != "")
            {
                ListItem item = new ListItem {
                    Value = DefaultSelectValue,
                    Text = DefaultSelectText
                };
                ddlCategories.Items.Insert(0, item);
            }
            if (ddlCategories.Items.FindByValue(SelectedValue) != null)
            {
                ddlCategories.ClearSelection();
                ddlCategories.Items.FindByValue(SelectedValue).Selected = true;
            }
        }

        public static void populateCountryList(int PortalID, DropDownList ddlCountry)
        {
            populateCountryList(PortalID, ddlCountry, "", "", "");
        }

        public static void populateCountryList(int PortalID, DropDownList ddlCountry, string DefaultValue)
        {
            populateCountryList(PortalID, ddlCountry, DefaultValue, "", "");
        }

        public static void populateCountryList(int PortalID, DropDownList ddlCountry, string DefaultValue, string NoneValue, string NoneText)
        {
            populateCountryList(PortalID, ddlCountry, DefaultValue, NoneValue, NoneText, false);
        }

        public static void populateCountryList(int PortalID, DropDownList ddlCountry, string DefaultValue, string NoneValue, string NoneText, bool PrefixCode)
        {
            ListItem item;
            IEnumerator enumerator;
            CategoryController controller = new CategoryController();
            string settingValue = "";
            ListEntryInfoCollection infos = new CountryLists().getCountryList(GetCurrentCulture());
            if (PortalID >= 0)
            {
                NB_Store_SettingsInfo info = new SettingsController().GetSetting(PortalID, "country.list", GetCurrentCulture());
                if (info != null)
                {
                    settingValue = info.SettingValue;
                }
            }
            ddlCountry.Items.Clear();
            try
            {
                enumerator = infos.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    ListEntryInfo current = (ListEntryInfo) enumerator.Current;
                    item = new ListItem {
                        Value = current.Value
                    };
                    if (PrefixCode)
                    {
                        item.Text = current.Value + " - " + current.Text;
                    }
                    else
                    {
                        item.Text = current.Text;
                    }
                    if (settingValue == "")
                    {
                        ddlCountry.Items.Add(item);
                    }
                    else if (settingValue.Contains(current.Text))
                    {
                        ddlCountry.Items.Add(item);
                    }
                }
            }
            finally
            {
                if (enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
            if (NoneValue != "")
            {
                item = new ListItem {
                    Value = NoneValue,
                    Text = NoneText
                };
                ddlCountry.Items.Insert(0, item);
            }
            if (ddlCountry.Items.FindByValue(DefaultValue) != null)
            {
                ddlCountry.SelectedValue = DefaultValue;
            }
        }

        public static void populateDropDownList(DropDownList ddl, string CSVList)
        {
            ddl.Items.Clear();
            string[] strArray = Strings.Split(CSVList, ",", -1, CompareMethod.Binary);
            int upperBound = strArray.GetUpperBound(0);
            for (int i = 0; i <= upperBound; i++)
            {
                ListItem item = new ListItem {
                    Value = i.ToString(),
                    Text = strArray[i]
                };
                ddl.Items.Add(item);
            }
        }

        public static Hashtable populateFeederSettings(int PortalId)
        {
            Hashtable hashtable2;
            Hashtable hashtable = new Hashtable();
            string xml = GetStoreSetting(PortalId, "feeder.settings", "None");
            XmlDataDocument document = new XmlDataDocument();
            try
            {
                IEnumerator enumerator;
                document.LoadXml(xml);
                try
                {
                    enumerator = document.SelectNodes("root/item").GetEnumerator();
                    while (enumerator.MoveNext())
                    {
                        XmlNode current = (XmlNode) enumerator.Current;
                        FeederSetInfo info = new FeederSetInfo {
                            Key = current.Attributes[0].InnerXml,
                            password = current.SelectSingleNode("./password").InnerXml,
                            reportref = current.SelectSingleNode("./reportref").InnerXml,
                            functionkey = current.SelectSingleNode("./functionkey").InnerXml,
                            cachemins = current.SelectSingleNode("./cachemins").InnerXml
                        };
                        hashtable.Add(info.Key, info);
                    }
                }
                finally
                {
                    if (enumerator is IDisposable)
                    {
                        (enumerator as IDisposable).Dispose();
                    }
                }
                hashtable2 = hashtable;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                hashtable2 = null;
                ProjectData.ClearProjectError();
            }
            return hashtable2;
        }

        public static void populateFileList(DropDownList lstFiles, string DirectoryPath, string Pattern)
        {
            string[] files = Directory.GetFiles(DirectoryPath, Pattern);
            lstFiles.Items.Clear();
            int upperBound = files.GetUpperBound(0);
            for (int i = 0; i <= upperBound; i++)
            {
                ListItem item = new ListItem {
                    Value = Path.GetFileName(files[i]),
                    Text = Path.GetFileName(files[i])
                };
                lstFiles.Items.Add(item);
            }
        }

        public static void populateFileList(PortalSettings PortalSettings, DropDownList lstFiles, string DirectoryPath, string EndsWith)
        {
            FolderInfo folder = FileSystemUtils.GetFolder(PortalSettings.PortalId, DirectoryPath);
            if (folder != null)
            {
                IEnumerator enumerator;
                ArrayList filesByFolder = FileSystemUtils.GetFilesByFolder(PortalSettings.PortalId, folder.FolderID);
                lstFiles.Items.Clear();
                try
                {
                    enumerator = filesByFolder.GetEnumerator();
                    while (enumerator.MoveNext())
                    {
                        DotNetNuke.Services.FileSystem.FileInfo current = (DotNetNuke.Services.FileSystem.FileInfo) enumerator.Current;
                        if (current.FileName.EndsWith(EndsWith))
                        {
                            ListItem item = new ListItem {
                                Value = Path.GetFileName(current.FileName),
                                Text = Path.GetFileName(current.FileName)
                            };
                            lstFiles.Items.Add(item);
                        }
                    }
                }
                finally
                {
                    if (enumerator is IDisposable)
                    {
                        (enumerator as IDisposable).Dispose();
                    }
                }
            }
        }

        public static object populateGenObject(DataList dlGenXML, object obj, int RowIndex = 0)
        {
            Collection collection3 = new Collection();
            Collection collection5 = new Collection();
            Collection collection2 = new Collection();
            Collection collection6 = new Collection();
            Collection collection4 = new Collection();
            Collection collection = new Collection();
            if ((dlGenXML.Items.Count > RowIndex) && (dlGenXML.Items.Count >= 1))
            {
                IEnumerator enumerator;
                IEnumerator enumerator2;
                IEnumerator enumerator3;
                IEnumerator enumerator4;
                IEnumerator enumerator5;
                DataListItem item = dlGenXML.Items[RowIndex];
                try
                {
                    enumerator = item.Controls.GetEnumerator();
                    while (enumerator.MoveNext())
                    {
                        Control current = (Control) enumerator.Current;
                        if (current is DropDownList)
                        {
                            collection3.Add(current, null, null, null);
                        }
                        if (current is CheckBox)
                        {
                            collection.Add(current, null, null, null);
                        }
                        if (current is RadioButtonList)
                        {
                            collection5.Add(current, null, null, null);
                        }
                        if (current is TextBox)
                        {
                            collection6.Add(current, null, null, null);
                        }
                    }
                }
                finally
                {
                    if (enumerator is IDisposable)
                    {
                        (enumerator as IDisposable).Dispose();
                    }
                }
                try
                {
                    enumerator2 = collection6.GetEnumerator();
                    while (enumerator2.MoveNext())
                    {
                        TextBox box2 = (TextBox) enumerator2.Current;
                        if (box2.Attributes["databind"] != null)
                        {
                            obj = RuntimeHelpers.GetObjectValue(assignByReflection(RuntimeHelpers.GetObjectValue(obj), box2.Attributes["databind"], box2.Text));
                        }
                    }
                }
                finally
                {
                    if (enumerator2 is IDisposable)
                    {
                        (enumerator2 as IDisposable).Dispose();
                    }
                }
                try
                {
                    enumerator3 = collection.GetEnumerator();
                    while (enumerator3.MoveNext())
                    {
                        CheckBox box = (CheckBox) enumerator3.Current;
                        if (box.Attributes["databind"] != null)
                        {
                            obj = RuntimeHelpers.GetObjectValue(assignByReflection(RuntimeHelpers.GetObjectValue(obj), box.Attributes["databind"], Conversions.ToString(box.Checked)));
                        }
                    }
                }
                finally
                {
                    if (enumerator3 is IDisposable)
                    {
                        (enumerator3 as IDisposable).Dispose();
                    }
                }
                try
                {
                    enumerator4 = collection3.GetEnumerator();
                    while (enumerator4.MoveNext())
                    {
                        DropDownList list = (DropDownList) enumerator4.Current;
                        if (list.Attributes["databind"] != null)
                        {
                            obj = RuntimeHelpers.GetObjectValue(assignByReflection(RuntimeHelpers.GetObjectValue(obj), list.Attributes["databind"], list.SelectedValue));
                        }
                    }
                }
                finally
                {
                    if (enumerator4 is IDisposable)
                    {
                        (enumerator4 as IDisposable).Dispose();
                    }
                }
                try
                {
                    enumerator5 = collection5.GetEnumerator();
                    while (enumerator5.MoveNext())
                    {
                        RadioButtonList list2 = (RadioButtonList) enumerator5.Current;
                        if (list2.Attributes["databind"] != null)
                        {
                            obj = RuntimeHelpers.GetObjectValue(assignByReflection(RuntimeHelpers.GetObjectValue(obj), list2.Attributes["databind"], list2.SelectedValue));
                        }
                    }
                }
                finally
                {
                    if (enumerator5 is IDisposable)
                    {
                        (enumerator5 as IDisposable).Dispose();
                    }
                }
            }
            return obj;
        }

        public static void populateShipMethodList(DropDownList ddlShipMethod, int PortalID, string SelectedValue = "")
        {
            IEnumerator enumerator;
            ArrayList shippingMethodList = new ShipController().GetShippingMethodList(PortalID);
            ddlShipMethod.Items.Clear();
            try
            {
                enumerator = shippingMethodList.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    NB_Store_ShippingMethodInfo current = (NB_Store_ShippingMethodInfo) enumerator.Current;
                    ListItem item = new ListItem {
                        Value = Conversions.ToString(current.ShipMethodID),
                        Text = current.MethodName
                    };
                    ddlShipMethod.Items.Add(item);
                }
            }
            finally
            {
                if (enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
            if (ddlShipMethod.Items.FindByValue(SelectedValue) != null)
            {
                ddlShipMethod.ClearSelection();
                ddlShipMethod.Items.FindByValue(SelectedValue).Selected = true;
            }
        }

        public static void populateStatusList(DropDownList ddlSearch, string DefaultSelectValue, string DefaultSelectText, string SelectedValue)
        {
            ListItem item;
            IEnumerator enumerator;
            ArrayList orderStatusList = new OrderController().GetOrderStatusList(GetCurrentCulture());
            ddlSearch.Items.Clear();
            try
            {
                enumerator = orderStatusList.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    NB_Store_OrderStatusInfo current = (NB_Store_OrderStatusInfo) enumerator.Current;
                    item = new ListItem {
                        Value = Conversions.ToString(current.OrderStatusID),
                        Text = current.OrderStatusText
                    };
                    ddlSearch.Items.Add(item);
                }
            }
            finally
            {
                if (enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
            if (DefaultSelectValue != "")
            {
                item = new ListItem {
                    Value = DefaultSelectValue,
                    Text = DefaultSelectText
                };
                ddlSearch.Items.Insert(0, item);
            }
            if (ddlSearch.Items.FindByValue(SelectedValue) != null)
            {
                ddlSearch.ClearSelection();
                ddlSearch.Items.FindByValue(SelectedValue).Selected = true;
            }
        }

        public static void populateTabsList(DropDownList lstTabs, PortalSettings PortalSettings, string DefaultValue)
        {
            lstTabs.DataSource = DotNetNuke.Common.Globals.GetPortalTabs(PortalSettings.DesktopTabs, false, true, false, true);
            lstTabs.DataTextField = "TabName";
            lstTabs.DataValueField = "TabId";
            lstTabs.DataBind();
            if ((DefaultValue != "") && (lstTabs.Items.FindByValue(DefaultValue) != null))
            {
                lstTabs.SelectedValue = DefaultValue;
            }
        }

        public static void populateTemplateList(int PortalId, DropDownList ddlTemplates, string FilterExt = "", string DefaultSelectValue = "", string DefaultSelectText = "", string SelectedValue = "")
        {
            ListItem item;
            Hashtable templateTable = new SettingsController().GetTemplateTable(PortalId);
            ICollection keys = templateTable.Keys;
            string[] array = new string[(templateTable.Count - 1) + 1];
            keys.CopyTo(array, 0);
            Array.Sort<string>(array);
            ddlTemplates.Items.Clear();
            foreach (string str in array)
            {
                item = new ListItem {
                    Value = str.ToString(),
                    Text = str.ToString()
                };
                if (FilterExt != "")
                {
                    if (item.Value.ToLower().EndsWith(FilterExt.ToLower()))
                    {
                        ddlTemplates.Items.Add(item);
                    }
                }
                else
                {
                    ddlTemplates.Items.Add(item);
                }
            }
            if (DefaultSelectValue != "")
            {
                item = new ListItem {
                    Value = DefaultSelectValue,
                    Text = DefaultSelectText
                };
                ddlTemplates.Items.Insert(0, item);
            }
            if (ddlTemplates.Items.FindByValue(SelectedValue) != null)
            {
                ddlTemplates.ClearSelection();
                ddlTemplates.Items.FindByValue(SelectedValue).Selected = true;
            }
        }

        public static string ProductPageName(ProductListInfo ProductListInfo, string CategoryName, string PortalName)
        {
            string expression = PortalName;
            if (ProductListInfo == null)
            {
                return expression;
            }
            string cacheKey = "PRDPG" + ProductListInfo.ProductID.ToString() + "_" + ProductListInfo.Lang;
            if ((DataCache.GetCache(cacheKey) == null) | GetStoreSettingBoolean(ProductListInfo.PortalID, "debug.mode"))
            {
                expression = GetStoreSettingText(ProductListInfo.PortalID, "ProductPageName.template", ProductListInfo.Lang);
                if (expression == "")
                {
                    expression = Strings.Replace(ProductListInfo.ProductName, "[TAG:PORTALNAME]", PortalName, 1, -1, CompareMethod.Binary);
                }
                else
                {
                    expression = Strings.Replace(Strings.Replace(Strings.Replace(Strings.Replace(Strings.Replace(Strings.Replace(Strings.Replace(Strings.Replace(Strings.Replace(expression, "[TAG:PRODUCTREF]", ProductListInfo.ProductRef, 1, -1, CompareMethod.Binary), "[TAG:PRODUCTNAME]", ProductListInfo.ProductName, 1, -1, CompareMethod.Binary), "[TAG:MANUFACTURER]", ProductListInfo.Manufacturer, 1, -1, CompareMethod.Binary), "[TAG:SUMMARY]", ProductListInfo.Summary, 1, -1, CompareMethod.Binary), "[TAG:TAGWORDS]", ProductListInfo.TagWords, 1, -1, CompareMethod.Binary), "[TAG:SEONAME]", ProductListInfo.SEOName, 1, -1, CompareMethod.Binary), "[TAG:CATEGORYNAME]", CategoryName, 1, -1, CompareMethod.Binary), "[TAG:PORTALNAME]", PortalName, 1, -1, CompareMethod.Binary), "[TAG:PORTALNAME]", PortalName, 1, -1, CompareMethod.Binary);
                    if (ProductListInfo.SEOPageTitle == "")
                    {
                        expression = new TokenStoreReplace(ProductListInfo).DoTokenReplace(expression);
                    }
                    else
                    {
                        expression = ProductListInfo.SEOPageTitle;
                    }
                }
                DataCache.SetCache(cacheKey, expression, DateAndTime.DateAdd(DateInterval.Day, 1.0, DateAndTime.Now));
                return expression;
            }
            return Conversions.ToString(DataCache.GetCache(cacheKey));
        }

        public static void PurgeAllFiles(PortalSettings PortalSettings)
        {
            Hashtable fileNamesInDB = new Hashtable();
            if (PortalSettings != null)
            {
                fileNamesInDB = getImageFileNamesInDB(PortalSettings.PortalId);
                PurgeFiles(PortalSettings, "productimages", fileNamesInDB);
                fileNamesInDB = getDocsFileNamesInDB(PortalSettings.PortalId);
                PurgeFiles(PortalSettings, "productdocs", fileNamesInDB);
                fileNamesInDB = getDocsFileNamesInDB(PortalSettings.PortalId);
                PurgeFiles(PortalSettings, "orderuploads", fileNamesInDB);
                fileNamesInDB = getDocsFileNamesInDB(PortalSettings.PortalId);
                PurgeLogFiles(PortalSettings);
            }
        }

        public static void PurgeFiles(PortalSettings PortalSettings, string PortalFolderName, Hashtable FileNamesInDB)
        {
            bool flag = false;
            FolderInfo folder = FileSystemUtils.GetFolder(PortalSettings.PortalId, PortalFolderName);
            if (folder != null)
            {
                IEnumerator enumerator;
                ArrayList filesByFolder = FileSystemUtils.GetFilesByFolder(PortalSettings.PortalId, folder.FolderID);
                try
                {
                    enumerator = filesByFolder.GetEnumerator();
                    while (enumerator.MoveNext())
                    {
                        DotNetNuke.Services.FileSystem.FileInfo current = (DotNetNuke.Services.FileSystem.FileInfo) enumerator.Current;
                        flag = true;
                        if (FileNamesInDB.ContainsKey(current.FileName))
                        {
                            flag = false;
                        }
                        if (flag)
                        {
                            try
                            {
                                FileSystemUtils.DeleteFile(PortalSettings.HomeDirectoryMapPath + PortalFolderName + @"\" + current.FileName, PortalSettings, true);
                            }
                            catch (Exception exception1)
                            {
                                ProjectData.SetProjectError(exception1);
                                Exception exception = exception1;
                                ProjectData.ClearProjectError();
                            }
                        }
                    }
                }
                finally
                {
                    if (enumerator is IDisposable)
                    {
                        (enumerator as IDisposable).Dispose();
                    }
                }
            }
        }

        public static void PurgeLogFiles(PortalSettings PortalSettings)
        {
            if (GetStoreSetting(PortalSettings.PortalId, "version", "None") != "")
            {
                string storeSetting = GetStoreSetting(PortalSettings.PortalId, "purgelogfiles.days");
                if (Versioned.IsNumeric(storeSetting))
                {
                    DateTime time = DateAndTime.DateAdd(DateInterval.Day, (double) (Conversions.ToInteger(storeSetting) * -1), DateAndTime.Now);
                    DirectoryInfo info = new DirectoryInfo(PortalSettings.HomeDirectoryMapPath + "LogFiles");
                    foreach (System.IO.FileInfo info2 in info.GetFiles("*.log"))
                    {
                        if (DateTime.Compare(DateAndTime.Today, info2.LastWriteTime.AddDays((double) Conversions.ToInteger(storeSetting))) >= 0)
                        {
                            info2.Delete();
                        }
                    }
                }
            }
        }

        public static void Redirect301(HttpResponse Response, string redirectURL)
        {
            Response.StatusCode = 0x12d;
            Response.Status = "301 Moved Permanently";
            Response.RedirectLocation = redirectURL;
        }

        public static void RegisterJS(string RegName, string JSFileName, string StoreInstallPath, Page Page)
        {
            if (!Page.ClientScript.IsClientScriptIncludeRegistered(RegName))
            {
                if (JSFileName.StartsWith("/"))
                {
                    Page.ClientScript.RegisterClientScriptInclude(RegName, JSFileName);
                }
                else
                {
                    Page.ClientScript.RegisterClientScriptInclude(RegName, StoreInstallPath + "js/" + JSFileName);
                }
            }
        }

        public static void removeCookieQueryValue(int PortalID, string CookieValueName, HttpCookie ListCookie)
        {
            setStoreCookieValue(PortalID, ListCookie, CookieValueName, "", 0.0);
        }

        public static void RemoveFiles(PortalSettings PortalSettings, string sourceDir)
        {
            FolderInfo folder = FileSystemUtils.GetFolder(PortalSettings.PortalId, sourceDir);
            if (folder != null)
            {
                IEnumerator enumerator;
                ArrayList filesByFolder = FileSystemUtils.GetFilesByFolder(PortalSettings.PortalId, folder.FolderID);
                try
                {
                    enumerator = filesByFolder.GetEnumerator();
                    while (enumerator.MoveNext())
                    {
                        DotNetNuke.Services.FileSystem.FileInfo current = (DotNetNuke.Services.FileSystem.FileInfo) enumerator.Current;
                        FileSystemUtils.DeleteFile(PortalSettings.HomeDirectoryMapPath + sourceDir + @"\" + current.FileName, PortalSettings, true);
                    }
                }
                finally
                {
                    if (enumerator is IDisposable)
                    {
                        (enumerator as IDisposable).Dispose();
                    }
                }
            }
        }

        public static void removeLangCache(int PortalID, string CacheKey)
        {
            try
            {
                LocaleCollection validLocales = GetValidLocales();
                int num2 = validLocales.Count - 1;
                for (int i = 0; i <= num2; i++)
                {
                    DictionaryEntry entry = validLocales[i];
                    DataCache.RemoveCache(((Locale) entry.Value).Code.ToLower() + CacheKey.ToLower() + PortalID.ToString());
                }
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                ProjectData.ClearProjectError();
            }
            DataCache.RemoveCache("none" + CacheKey.ToLower() + PortalID.ToString());
        }

        public static void removeStoreCookie(int PortalID, string CookieName)
        {
            string str = "NB_Store2_" + CookieName + "_Portal" + PortalID.ToString();
            HttpCookie cookie = HttpContext.Current.Request.Cookies[str];
            if (cookie != null)
            {
                cookie.Expires = DateTime.Now.AddYears(-30);
                HttpContext.Current.Response.Cookies.Add(cookie);
            }
        }

        public static void removeStoreTemplateCache(int PortalID)
        {
            IEnumerator enumerator;
            IEnumerator enumerator2;
            SettingsController controller = new SettingsController();
            ArrayList list = controller.GetSettingsTexts(PortalID, GetCurrentCulture(), true, "");
            try
            {
                enumerator = list.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    NB_Store_SettingsTextInfo current = (NB_Store_SettingsTextInfo) enumerator.Current;
                    removeLangCache(PortalID, "TX_" + current.SettingName);
                }
            }
            finally
            {
                if (enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
            list = controller.GetSettingList(PortalID, GetCurrentCulture(), true, "");
            try
            {
                enumerator2 = list.GetEnumerator();
                while (enumerator2.MoveNext())
                {
                    NB_Store_SettingsInfo info = (NB_Store_SettingsInfo) enumerator2.Current;
                    removeLangCache(PortalID, info.SettingName);
                }
            }
            finally
            {
                if (enumerator2 is IDisposable)
                {
                    (enumerator2 as IDisposable).Dispose();
                }
            }
        }

        public static string RenderDataList(int PortalID, string TemplateName, string Lang)
        {
            object objectValue = RuntimeHelpers.GetObjectValue(new object());
            return RenderDataList(PortalID, TemplateName, Lang, RuntimeHelpers.GetObjectValue(objectValue));
        }

        public static string RenderDataList(int PortalID, string TemplateName, string Lang, object objInfo)
        {
            ArrayList list = new ArrayList();
            DataList list2 = new DataList();
            string templateText = HttpUtility.HtmlDecode(GetStoreSettingText(PortalID, TemplateName, Lang));
            list2.ItemTemplate = new GenXMLTemplate(templateText);
            list.Add(RuntimeHelpers.GetObjectValue(objInfo));
            list2.DataSource = list;
            list2.DataBind();
            StringBuilder sb = new StringBuilder();
            StringWriter writer2 = new StringWriter(sb);
            HtmlTextWriter writer = new HtmlTextWriter(writer2);
            list2.RenderControl(writer);
            return sb.ToString();
        }

        public static string ReplaceFileExt(string FileName, string NewExt)
        {
            return (Path.GetDirectoryName(FileName) + @"\" + Path.GetFileNameWithoutExtension(FileName) + NewExt);
        }

        public static void ReplaceXMLatt(XmlDataDocument xmlDoc, string XPath, string NewValue)
        {
            XmlNode node = xmlDoc.SelectSingleNode(XPath);
            if (node != null)
            {
                node.Attributes["value"].InnerText = NewValue;
            }
        }

        public static void ReplaceXMLNode(XmlDataDocument xmlDoc, string XPath, string NewValue, bool cdata = true)
        {
            XmlNode node = xmlDoc.SelectSingleNode(XPath);
            if (node != null)
            {
                if (cdata)
                {
                    node.InnerXml = "<![CDATA[" + NewValue + "]]>";
                }
                else
                {
                    node.InnerXml = NewValue;
                }
            }
        }

        public static decimal RoundToStoreCurrency(double Value)
        {
            return RoundToStoreCurrency(PortalController.GetCurrentPortalSettings().PortalId, Value);
        }

        public static decimal RoundToStoreCurrency(int PortalID, double Value)
        {
            return CurrencyStringToDecimal(PortalID, FormatToStoreCurrency(PortalID, Value));
        }

        public static bool SafeDNNVersion(ref int major, ref int minor, ref int revision, ref int build)
        {
            Version version = System.Reflection.Assembly.GetAssembly(typeof(DotNetNuke.Common.Globals)).GetName().Version;
            if (version != null)
            {
                major = version.Major;
                minor = version.Minor;
                build = version.Build;
                revision = version.Revision;
                return true;
            }
            major = 0;
            minor = 0;
            build = 0;
            revision = 0;
            return false;
        }

        public static void SendEmailToAdministrator(int Portalid, string SubjectText, string EmailBody)
        {
            DotNetNuke.Services.Mail.Mail.SendMail(GetStoreEmail(Portalid), GetAdministratorEmail(Portalid), "", SubjectText, EmailBody, "", "TEXT", "", "", "", "");
        }

        public static void SendEmailToClient(int Portalid, string ClientEmail, string SubjectText, string EmailTemplateName, string Lang)
        {
            SendEmailToClient(Portalid, ClientEmail, SubjectText, null, EmailTemplateName, Lang);
        }

        public static void SendEmailToClient(int Portalid, string ClientEmail, string SubjectText, NB_Store_OrdersInfo objOrderInfo, string EmailTemplateName, string Lang)
        {
            if ((objOrderInfo != null) && (objOrderInfo.Email != ""))
            {
                ClientEmail = objOrderInfo.Email;
            }
            SendStoreEmail(Portalid, ClientEmail, SubjectText, objOrderInfo, EmailTemplateName, Lang);
        }

        public static void SendEmailToManager(int Portalid, string SubjectText, string EmailTemplateName)
        {
            SendEmailToManager(Portalid, SubjectText, null, EmailTemplateName);
        }

        public static void SendEmailToManager(int Portalid, string SubjectText, NB_Store_OrdersInfo objOrderInfo, string EmailTemplateName)
        {
            string clientEmail = "";
            clientEmail = GetMerchantEmail(Portalid);
            SendStoreEmail(Portalid, clientEmail, SubjectText, objOrderInfo, EmailTemplateName, GetMerchantCulture(Portalid));
        }

        public static void SendStoreEmail(int Portalid, string ClientEmail, string SubjectText, NB_Store_OrdersInfo objOrderInfo, string EmailTemplateName, string Lang)
        {
            SettingsController controller = new SettingsController();
            string mailFrom = "";
            string strSourceText = "";
            mailFrom = GetStoreEmail(Portalid);
            NB_Store_SettingsTextInfo info = controller.GetSettingsText(Portalid, EmailTemplateName, Lang);
            if (info != null)
            {
                strSourceText = HttpUtility.HtmlDecode(info.SettingText);
            }
            SubjectText = HttpUtility.HtmlDecode(GetStoreSettingText(Portalid, EmailTemplateName + "subject", Lang));
            if (objOrderInfo != null)
            {
                TokenStoreReplace replace = new TokenStoreReplace(objOrderInfo, Lang);
                strSourceText = replace.DoTokenReplace(strSourceText, true);
                SubjectText = replace.DoTokenReplace(SubjectText);
            }
            if (GetStoreSetting(Portalid, "debug.email") != "")
            {
                ClientEmail = GetStoreSetting(Portalid, "debug.email");
            }
            DotNetNuke.Services.Mail.Mail.SendMail(mailFrom, ClientEmail, "", SubjectText, strSourceText, "", "HTML", "", "", "", "");
        }

        public static void setAdminCookieValue(int PortalID, string ValueID, string Value)
        {
            setStoreCookieValue(PortalID, "Admin", ValueID, Value, 0.0);
        }

        private static void setCookieURLparam(int PortalID, string ValueID, string Value)
        {
            if (Value.EndsWith("="))
            {
                Value = "";
            }
            setStoreCookieValue(PortalID, "UrlCookieInfo", ValueID, Value, 0.0);
        }

        public static void setGridViewEnabled(GridViewRow row, string CtrlIdAsCSVlist, bool blnVisible)
        {
            string[] strArray = CtrlIdAsCSVlist.Split(new char[] { ',' });
            int upperBound = strArray.GetUpperBound(0);
            for (int i = 0; i <= upperBound; i++)
            {
                Control control = row.FindControl(strArray[i]);
                if (control != null)
                {
                    if (control is TextBox)
                    {
                        ((TextBox) control).Enabled = blnVisible;
                    }
                    else if (control is CheckBox)
                    {
                        ((CheckBox) control).Enabled = blnVisible;
                    }
                    else if (control is DropDownList)
                    {
                        ((DropDownList) control).Enabled = blnVisible;
                    }
                    else if (control is RadioButton)
                    {
                        ((RadioButton) control).Enabled = blnVisible;
                    }
                    else if (control is RadioButtonList)
                    {
                        ((RadioButtonList) control).Enabled = blnVisible;
                    }
                }
            }
        }

        public static void setGridViewVisible(GridViewRow row, string CtrlIdAsCSVlist, bool blnVisible)
        {
            string[] strArray = CtrlIdAsCSVlist.Split(new char[] { ',' });
            int upperBound = strArray.GetUpperBound(0);
            for (int i = 0; i <= upperBound; i++)
            {
                Control control = row.FindControl(strArray[i]);
                if (control != null)
                {
                    control.Visible = blnVisible;
                }
            }
        }

        public static void setLangCache(int PortalID, string CacheKey, string Lang, NB_Store_SettingsInfo objS)
        {
            if (objS.SettingValue.Contains("["))
            {
                objS.SettingValue = new TokenStoreReplace(PortalID, Lang).replaceTemplates(objS.SettingValue, Lang, 1);
            }
            setLangCache(PortalID, CacheKey, Lang, objS, 60);
        }

        public static void setLangCache(int PortalID, string CacheKey, string Lang, NB_Store_SettingsTextInfo objS)
        {
            if (objS.SettingText.Contains("["))
            {
                objS.SettingText = new TokenStoreReplace(PortalID, Lang).replaceTemplates(objS.SettingText, Lang, 1);
            }
            setLangCache(PortalID, CacheKey, Lang, objS, 60);
        }

        public static void setLangCache(int PortalID, string CacheKey, string Lang, object objObject)
        {
            setLangCache(PortalID, CacheKey, Lang, RuntimeHelpers.GetObjectValue(objObject), 60);
        }

        public static void setLangCache(int PortalID, string CacheKey, string Lang, object objObject, int CahceMins)
        {
            DataCache.SetCache(Lang.ToLower() + CacheKey.ToLower() + PortalID.ToString(), RuntimeHelpers.GetObjectValue(objObject), DateAndTime.DateAdd(DateInterval.Minute, (double) CahceMins, DateAndTime.Now));
        }

        public static void setStoreCookieValue(int PortalID, string CookieName, string ValueID, string Value, double ExpireDays = 30.0)
        {
            string name = "NB_Store2_" + CookieName + "_Portal" + PortalID.ToString();
            HttpCookie objCookie = HttpContext.Current.Request.Cookies[name];
            if (objCookie == null)
            {
                objCookie = new HttpCookie(name);
            }
            setStoreCookieValue(PortalID, objCookie, ValueID, Value, ExpireDays);
        }

        public static void setStoreCookieValue(int PortalID, HttpCookie objCookie, string ValueID, string Value, double ExpireDays = 30.0)
        {
            if (objCookie != null)
            {
                if (Value == null)
                {
                    objCookie[ValueID] = "";
                }
                else
                {
                    objCookie[ValueID] = StoreEncrypt(PortalID, Value);
                }
                if (ExpireDays == Conversions.ToDouble("0"))
                {
                    objCookie.Expires = DateTime.MinValue;
                }
                else
                {
                    objCookie.Expires = DateAndTime.DateAdd(DateInterval.Day, ExpireDays, DateAndTime.Today);
                }
                HttpContext.Current.Response.Cookies.Add(objCookie);
            }
        }

        public static void SetStoreSetting(int Portalid, string SettingName, string SettingValue, string Lang, bool IsHostOnly)
        {
            SettingsController controller = new SettingsController();
            NB_Store_SettingsInfo objInfo = controller.GetSetting(Portalid, SettingName, Lang);
            if (objInfo == null)
            {
                objInfo = new NB_Store_SettingsInfo {
                    SettingName = SettingName,
                    SettingValue = SettingValue,
                    Lang = Lang,
                    HostOnly = IsHostOnly,
                    PortalID = Portalid
                };
                if (SettingName.EndsWith(".email"))
                {
                    objInfo.GroupRef = "root/notifications";
                }
                else if (SettingName.EndsWith(".emailsubject"))
                {
                    objInfo.GroupRef = "root/notifications";
                }
                else if (SettingName.EndsWith(".plugin"))
                {
                    objInfo.GroupRef = "root/system/backoffice";
                }
                else
                {
                    objInfo.GroupRef = "root/system/misc";
                }
            }
            else
            {
                objInfo.HostOnly = IsHostOnly;
                objInfo.SettingValue = SettingValue;
            }
            controller.UpdateObjSetting(objInfo);
        }

        public static void setUrlCookieInfo(int PortalID, HttpRequest Request)
        {
            setCookieURLparam(PortalID, "CatID", "CatID=" + Request.QueryString["CatID"]);
            setCookieURLparam(PortalID, "RtnTab", "RtnTab=" + Request.QueryString["RtnTab"]);
            setCookieURLparam(PortalID, "PageIndex", "PageIndex=" + Request.QueryString["PageIndex"]);
            setCookieURLparam(PortalID, "orderby", "orderby=" + Request.QueryString["orderby"]);
            setCookieURLparam(PortalID, "currentpage", "currentpage=" + Request.QueryString["currentpage"]);
            setCookieURLparam(PortalID, "wishlist", "wishlist=" + Request.QueryString["wishlist"]);
            setCookieURLparam(PortalID, "Search", "Search=" + Request.QueryString["Search"]);
            setCookieURLparam(PortalID, "desc", "desc=" + Request.QueryString["desc"]);
        }

        public static string StoreDecrypt(int PortalID, string Value)
        {
            PortalSecurity security = new PortalSecurity();
            string storeSetting = GetStoreSetting(PortalID, "encrypt.key");
            if (storeSetting == "")
            {
                return Value;
            }
            if (Value == null)
            {
                return "";
            }
            return security.Decrypt(storeSetting, Value);
        }

        public static string StoreEncrypt(int PortalID, string Value)
        {
            PortalSecurity security = new PortalSecurity();
            string storeSetting = GetStoreSetting(PortalID, "encrypt.key");
            if (storeSetting == "")
            {
                return Value;
            }
            if (Value == null)
            {
                return "";
            }
            return security.Encrypt(storeSetting, Value);
        }

        public static void UpdateLog(string LogMsg)
        {
            UpdateLog(-1, LogMsg);
        }

        public static void UpdateLog(int Userid, string LogMsg)
        {
            if (LogMsg != "")
            {
                string username = "";
                PortalSettings currentPortalSettings = PortalController.GetCurrentPortalSettings();
                if (Userid > -1)
                {
                    username = UserController.GetUserById(currentPortalSettings.PortalId, Userid).Username;
                }
                new LogText { FileName = currentPortalSettings.HomeDirectoryMapPath + @"LogFiles\NB_Store_" + Conversions.ToString(DateAndTime.Today.Year) + Strings.Format(DateAndTime.Today.Month, "00") + Strings.Format(DateAndTime.Today.Day, "00") + ".Log" }.Log(DateAndTime.Now.ToString() + " - " + username + " - " + LogMsg);
            }
        }

        public static int VersionCompare(string TestVersion, string CompareVersion)
        {
            int num;
            if (TestVersion == "")
            {
                TestVersion = "0.0.0";
            }
            if (CompareVersion == "")
            {
                CompareVersion = "0.0.0";
            }
            try
            {
                string[] strArray2 = Strings.Split(TestVersion, ".", -1, CompareMethod.Binary);
                string[] strArray = Strings.Split(CompareVersion, ".", -1, CompareMethod.Binary);
                if ((strArray2.GetUpperBound(0) == 2) & (strArray.GetUpperBound(0) == 2))
                {
                    if (!(((Conversions.ToInteger(strArray2[0]) == Conversions.ToInteger(strArray[0])) & (Conversions.ToInteger(strArray2[1]) == Conversions.ToInteger(strArray[1]))) & (Conversions.ToInteger(strArray2[2]) == Conversions.ToInteger(strArray[2]))))
                    {
                        if (Conversions.ToInteger(strArray2[0]) < Conversions.ToInteger(strArray[0]))
                        {
                            return -1;
                        }
                        if (Conversions.ToInteger(strArray2[0]) > Conversions.ToInteger(strArray[0]))
                        {
                            return 1;
                        }
                        if (Conversions.ToInteger(strArray2[1]) < Conversions.ToInteger(strArray[1]))
                        {
                            return -1;
                        }
                        if (Conversions.ToInteger(strArray2[1]) > Conversions.ToInteger(strArray[1]))
                        {
                            return 1;
                        }
                        if (Conversions.ToInteger(strArray2[2]) < Conversions.ToInteger(strArray[2]))
                        {
                            return -1;
                        }
                        if (Conversions.ToInteger(strArray2[2]) > Conversions.ToInteger(strArray[2]))
                        {
                            return 1;
                        }
                    }
                    return 0;
                }
                num = 0;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                num = 0;
                ProjectData.ClearProjectError();
            }
            return num;
        }

        public static string XSLTrans(string xmlData, string XslFilePath)
        {
            string str;
            try
            {
                XmlDataDocument document = new XmlDataDocument();
                document.LoadXml(xmlData);
                XslCompiledTransform transform = new XslCompiledTransform();
                transform.Load(XslFilePath);
                StringWriter writer = new StringWriter();
                transform.Transform((IXPathNavigable) document, null, (TextWriter) writer);
                str = writer.ToString();
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                str = exception1.ToString();
                ProjectData.ClearProjectError();
            }
            return str;
        }

        public static string XSLTransByTemplate(string xmlData, string XslTemplateName)
        {
            string str3;
            bool flag = false;
            XmlDocument document = new XmlDocument();
            string xslData = "";
            PortalSettings currentPortalSettings = PortalController.GetCurrentPortalSettings();
            string settingName = XslTemplateName;
            flag = GetStoreSettingBoolean(currentPortalSettings.PortalId, "debug.mode", "None");
            xslData = HttpUtility.HtmlDecode(GetStoreSettingText(currentPortalSettings.PortalId, settingName, GetCurrentCulture()));
            if (xslData == "")
            {
                try
                {
                    document.Load(currentPortalSettings.HomeDirectoryMapPath + settingName);
                    xslData = document.OuterXml;
                }
                catch (Exception exception1)
                {
                    ProjectData.SetProjectError(exception1);
                    Exception exception = exception1;
                    xslData = "";
                    ProjectData.ClearProjectError();
                }
            }
            if (flag)
            {
                document = new XmlDocument();
                try
                {
                    document.LoadXml(xmlData);
                    document.Save(currentPortalSettings.HomeDirectoryMapPath + "debug_" + Strings.Replace(XslTemplateName, ".xsl", "", 1, -1, CompareMethod.Binary) + ".xml");
                }
                catch (Exception exception4)
                {
                    ProjectData.SetProjectError(exception4);
                    Exception exception2 = exception4;
                    ProjectData.ClearProjectError();
                }
            }
            if (xslData == "")
            {
                return ("NO XSL FOUND: " + XslTemplateName);
            }
            try
            {
                str3 = XSLTransInMemory(xmlData, xslData);
            }
            catch (Exception exception5)
            {
                ProjectData.SetProjectError(exception5);
                UpdateLog("XML ERROR on " + XslTemplateName + " : " + exception5.ToString());
                str3 = "";
                ProjectData.ClearProjectError();
            }
            return str3;
        }

        public static string XSLTransInMemory(string xmlData, string XslData)
        {
            string str;
            try
            {
                XmlDataDocument document = new XmlDataDocument();
                document.LoadXml(xmlData);
                MemoryStream input = new MemoryStream(Encoding.UTF8.GetBytes(XslData)) {
                    Position = 0L
                };
                XmlReader stylesheet = new XmlTextReader(input);
                XslCompiledTransform transform = new XslCompiledTransform();
                transform.Load(stylesheet);
                StringWriter writer = new StringWriter();
                transform.Transform((IXPathNavigable) document, null, (TextWriter) writer);
                str = writer.ToString();
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                str = exception1.ToString();
                ProjectData.ClearProjectError();
            }
            return str;
        }
    }
}

